{"_id":"type-spec","_rev":"34-cbf904ec69665be9ffc10e5e58387bac","name":"type-spec","description":"A minimalist approach to dynamic type checking in JavaScript","dist-tags":{"latest":"0.0.6-alpha"},"versions":{"0.0.1-alpha":{"name":"type-spec","version":"0.0.1-alpha","keywords":["Type Checking","Dynamic Types"],"author":{"name":"mastergray"},"license":"MIT","_id":"type-spec@0.0.1-alpha","maintainers":[{"name":"mastergray","email":"me@mastergray.com"}],"homepage":"https://github.com/mastergray/type-spec#readme","bugs":{"url":"https://github.com/mastergray/type-spec/issues"},"dist":{"shasum":"2091732eb5082c3831f3e9ab6cc3d03c3599d60b","tarball":"https://registry.npmjs.org/type-spec/-/type-spec-0.0.1-alpha.tgz","fileCount":8,"integrity":"sha512-9M0FjmWocpDD3W7iTGe7LC5Zh8E++R7dt2n/Trs/tnGx9C/D1nRhMPaem6HtWHkFivqOQix0ZwVKDJ9jimOYmA==","signatures":[{"sig":"MEYCIQCAcT8HzLR8f3T5yE37PylerJJSIUFsKjeNrlm+V4h5jAIhAIILL3wtj8rPiSq8dozWRU/gKG8EyiVw9qAVorRCShWf","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":24310},"main":"./src/index.js","type":"module","gitHead":"26071398b46ba826fe278ce6fb447f4903bc7d75","scripts":{"staging":"nodemon --watch ./ -e js,json,ts ./test/index.js"},"_npmUser":{"name":"mastergray","email":"me@mastergray.com"},"repository":{"url":"git+https://github.com/mastergray/type-spec.git","type":"git"},"_npmVersion":"10.5.0","description":"A minimalist approach to type checking in JavaScript","directories":{},"_nodeVersion":"21.7.3","nodemonConfig":{"ignore":["node_modules/**/*"]},"_hasShrinkwrap":false,"devDependencies":{"nodemon":"^3.1.0"},"_npmOperationalInternal":{"tmp":"tmp/type-spec_0.0.1-alpha_1714844756971_0.9563716455156777","host":"s3://npm-registry-packages"}},"0.0.2-alpha":{"name":"type-spec","version":"0.0.2-alpha","keywords":["Type Checking","Dynamic Types"],"author":{"name":"mastergray"},"license":"MIT","_id":"type-spec@0.0.2-alpha","maintainers":[{"name":"mastergray","email":"me@mastergray.com"}],"homepage":"https://github.com/mastergray/type-spec#readme","bugs":{"url":"https://github.com/mastergray/type-spec/issues"},"dist":{"shasum":"e4e62d35192a3106c2b3c96e890e6e5a88629ebb","tarball":"https://registry.npmjs.org/type-spec/-/type-spec-0.0.2-alpha.tgz","fileCount":8,"integrity":"sha512-Jh50ipjHaRy9ZnmHdYbhDUuC/VS39PGFy9JPdKF1BnH5NKFEA1Fi1KXAfzAGDjZYQ3RDAlFMS9SF9z+sI401dQ==","signatures":[{"sig":"MEQCIAaqYXuqZpZ7tvnjjfD9ueitu6btXUUQ7fmhtdRu7ESsAiBXITGPkvU9nlVM80s9pmmD68JCsaaRJUzZui+1Ruutag==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":29793},"main":"./src/index.js","type":"module","gitHead":"bafda948d8cb37b6796d147c48fa1dcb23332ae4","scripts":{"staging":"nodemon --watch ./ -e js,json,ts ./test/index.js"},"_npmUser":{"name":"mastergray","email":"me@mastergray.com"},"repository":{"url":"git+https://github.com/mastergray/type-spec.git","type":"git"},"_npmVersion":"10.5.0","description":"A minimalist approach to type checking in JavaScript","directories":{},"_nodeVersion":"21.7.3","nodemonConfig":{"ignore":["node_modules/**/*"]},"_hasShrinkwrap":false,"devDependencies":{"nodemon":"^3.1.0"},"_npmOperationalInternal":{"tmp":"tmp/type-spec_0.0.2-alpha_1714936363776_0.993551049318407","host":"s3://npm-registry-packages"}},"0.0.3-alpha":{"name":"type-spec","version":"0.0.3-alpha","keywords":["Type Checking","Dynamic Types","Type System","Types"],"author":{"name":"mastergray"},"license":"MIT","_id":"type-spec@0.0.3-alpha","maintainers":[{"name":"mastergray","email":"me@mastergray.com"}],"homepage":"https://github.com/mastergray/type-spec#readme","bugs":{"url":"https://github.com/mastergray/type-spec/issues"},"dist":{"shasum":"6adc452a6ddefe3e5ddf99d9c287fa69082d5471","tarball":"https://registry.npmjs.org/type-spec/-/type-spec-0.0.3-alpha.tgz","fileCount":8,"integrity":"sha512-gEePn4WsWfz4gVZR6aWf9hiYqiIotvM20b77Uvthr6uBaFvyAHr9pW3k3hszEXviRF4Gj5bJ8ZcPcvTSvzdcgQ==","signatures":[{"sig":"MEQCIE/RcDdOGxHE+M4GQJV5gXvbogV3348NAl1BsRD7liabAiBXvaPfJat7DxUuWPqilOKVUxnzRsDkFj0fI8d+yks/tQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":32330},"main":"./src/index.js","type":"module","gitHead":"d03b3084cd91847c47dff46b54df7d7b36531083","scripts":{"staging":"nodemon --watch ./ -e js,json,ts ./test/index.js"},"_npmUser":{"name":"mastergray","email":"me@mastergray.com"},"repository":{"url":"git+https://github.com/mastergray/type-spec.git","type":"git"},"_npmVersion":"10.5.0","description":"A minimalist approach to dynamic type checking in JavaScript","directories":{},"_nodeVersion":"21.7.3","nodemonConfig":{"ignore":["node_modules/**/*"]},"_hasShrinkwrap":false,"devDependencies":{"nodemon":"^3.1.0"},"_npmOperationalInternal":{"tmp":"tmp/type-spec_0.0.3-alpha_1715128600894_0.4894832386441521","host":"s3://npm-registry-packages"}},"0.0.4-alpha":{"name":"type-spec","version":"0.0.4-alpha","keywords":["Type Checking","Type Safety","Dynamic Types","Type System","Types","Data Transformations"],"author":{"name":"mastergray"},"license":"MIT","_id":"type-spec@0.0.4-alpha","maintainers":[{"name":"mastergray","email":"me@mastergray.com"}],"homepage":"https://github.com/mastergray/type-spec#readme","bugs":{"url":"https://github.com/mastergray/type-spec/issues"},"dist":{"shasum":"93940f92e66acf4982c60501f30825e510e25e75","tarball":"https://registry.npmjs.org/type-spec/-/type-spec-0.0.4-alpha.tgz","fileCount":8,"integrity":"sha512-OKrBaPhVfwGwdETZVzVTeR3hiOCTmMUxvdKugO0DEQiof0477zervxEc0oLajQq7YVnBewCUzvOzYRgAtkfkNQ==","signatures":[{"sig":"MEUCIQCrhsF7y34uNQDL4mkiAzJwUhlZ4L/2yqKm6jOoQasF/QIgG0Y2Vi+gxsvVgDoc+3dKk/ovsCR69nlA66567SxpqlI=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":40288},"main":"./src/index.js","type":"module","gitHead":"a3be38618c54fa4b2246ff0ad1d6ac0c6c515a9d","scripts":{"staging":"nodemon --watch ./ -e js,json,ts ./test/index.js"},"_npmUser":{"name":"mastergray","email":"me@mastergray.com"},"repository":{"url":"git+https://github.com/mastergray/type-spec.git","type":"git"},"_npmVersion":"10.5.0","description":"A minimalist approach to dynamic type checking in JavaScript","directories":{},"_nodeVersion":"21.7.3","nodemonConfig":{"ignore":["node_modules/**/*"]},"_hasShrinkwrap":false,"devDependencies":{"nodemon":"^3.1.0"},"_npmOperationalInternal":{"tmp":"tmp/type-spec_0.0.4-alpha_1716744048494_0.7614091357733037","host":"s3://npm-registry-packages"}},"0.0.5-alpha":{"name":"type-spec","version":"0.0.5-alpha","keywords":["Type Checking","Type Safety","Dynamic Types","Type System","Types","Data Transformations","Functional Programming"],"author":{"name":"mastergray"},"license":"MIT","_id":"type-spec@0.0.5-alpha","maintainers":[{"name":"mastergray","email":"me@mastergray.com"}],"homepage":"https://github.com/mastergray/type-spec#readme","bugs":{"url":"https://github.com/mastergray/type-spec/issues"},"dist":{"shasum":"3555534a57bca47eee81f132e43a8271b5a71b6e","tarball":"https://registry.npmjs.org/type-spec/-/type-spec-0.0.5-alpha.tgz","fileCount":11,"integrity":"sha512-hns65hAS34rQAm27zBwUD5KVdXQzM7TL1B7s5u9FvrUbhxiosEDkj/5jbMutdgcApMASsUpoTDCf3UtgkZJ4xA==","signatures":[{"sig":"MEUCIBKtXjB42cBB7ueJnjmy9SXM0aaBuHNRkBVhEQc72fhxAiEAmShjsVxV+iKhBooSGyxRGoNO9lMSCVSB/xogw2bSqAU=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":56603},"main":"./src/index.js","type":"module","gitHead":"ae844c4f675a986555f971944c86688f7d4b24da","scripts":{"staging":"nodemon --watch ./ -e js,json,ts ./test/index.js"},"_npmUser":{"name":"mastergray","email":"me@mastergray.com"},"repository":{"url":"git+https://github.com/mastergray/type-spec.git","type":"git"},"_npmVersion":"10.5.0","description":"A minimalist approach to dynamic type checking in JavaScript","directories":{},"_nodeVersion":"21.7.3","nodemonConfig":{"ignore":["node_modules/**/*"]},"_hasShrinkwrap":false,"devDependencies":{"nodemon":"^3.1.0"},"_npmOperationalInternal":{"tmp":"tmp/type-spec_0.0.5-alpha_1717289053841_0.8330642708027223","host":"s3://npm-registry-packages"}},"0.0.6-alpha":{"name":"type-spec","version":"0.0.6-alpha","description":"A minimalist approach to dynamic type checking in JavaScript","main":"./src/index.js","type":"module","scripts":{"staging":"nodemon --watch ./ -e js,json,ts ./test/index.js"},"nodemonConfig":{"ignore":["node_modules/**/*"]},"repository":{"type":"git","url":"git+https://github.com/mastergray/type-spec.git"},"keywords":["Type Checking","Type Safety","Dynamic Types","Type System","Types","Validation"],"bugs":{"url":"https://github.com/mastergray/type-spec/issues"},"author":{"name":"mastergray"},"license":"MIT","homepage":"https://github.com/mastergray/type-spec#readme","devDependencies":{"nodemon":"^3.1.0"},"_id":"type-spec@0.0.6-alpha","gitHead":"cc23f04a835a4773067ecb86d5a9dc52c1aa5bb1","_nodeVersion":"21.7.3","_npmVersion":"10.5.0","dist":{"integrity":"sha512-SljKoDVblm0TX54jU919ldr9dtErNoBn/Ygfsksg4eEdlSWCSsqCc7N56QLzq+xx3cFa6MHIYj7REWXqimbz+w==","shasum":"b9b982dec585c5fced1876f2a90c486001e16ff6","tarball":"https://registry.npmjs.org/type-spec/-/type-spec-0.0.6-alpha.tgz","fileCount":12,"unpackedSize":66226,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHLE8wBBohPO0RKP/+r/j9AHZNqQLuEAJydqeZbzyZXnAiEA74+0f+7ULnrVfk5ZktEPSnSsVTrp9ncFx/AhD/ioptE="}]},"_npmUser":{"name":"mastergray","email":"me@mastergray.com"},"directories":{},"maintainers":[{"name":"mastergray","email":"me@mastergray.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/type-spec_0.0.6-alpha_1717879759806_0.3429289782442282"},"_hasShrinkwrap":false}},"time":{"created":"2024-05-04T17:45:56.971Z","modified":"2024-06-08T20:49:20.148Z","0.0.1":"2015-08-05T01:52:29.352Z","0.0.2":"2015-08-05T02:13:36.649Z","0.0.3":"2015-08-05T10:49:44.230Z","0.0.4":"2015-08-05T15:02:14.411Z","0.0.5":"2015-08-05T17:17:28.312Z","0.0.6":"2015-08-06T07:25:16.318Z","0.0.7":"2015-08-07T11:15:23.176Z","0.0.8":"2015-08-07T11:26:38.794Z","0.0.9":"2015-08-07T11:41:42.665Z","0.0.10":"2015-08-07T14:24:21.370Z","0.0.11":"2015-08-07T17:42:51.309Z","0.1.0":"2015-08-09T15:16:03.580Z","0.1.1":"2015-08-20T03:15:52.840Z","0.1.2":"2015-08-20T03:20:48.878Z","0.1.3":"2015-08-20T03:39:44.308Z","0.2.0":"2015-08-23T15:25:48.365Z","0.2.1":"2015-08-23T16:06:20.964Z","0.3.0":"2015-08-23T18:41:47.275Z","0.3.1":"2015-08-27T07:24:59.698Z","0.3.2":"2015-08-27T10:07:43.067Z","0.3.3":"2015-08-30T18:40:34.425Z","0.3.4":"2015-09-08T04:05:55.131Z","0.3.5":"2015-09-08T04:32:33.734Z","0.3.6":"2015-09-08T04:36:03.170Z","0.4.0":"2015-09-15T13:12:38.599Z","0.0.1-alpha":"2024-05-04T17:45:57.126Z","0.0.2-alpha":"2024-05-05T19:12:43.929Z","0.0.3-alpha":"2024-05-08T00:36:41.149Z","0.0.4-alpha":"2024-05-26T17:20:48.678Z","0.0.5-alpha":"2024-06-02T00:44:14.024Z","0.0.6-alpha":"2024-06-08T20:49:19.994Z"},"maintainers":[{"name":"mastergray","email":"me@mastergray.com"}],"author":{"name":"mastergray"},"repository":{"type":"git","url":"git+https://github.com/mastergray/type-spec.git"},"keywords":["Type Checking","Type Safety","Dynamic Types","Type System","Types","Validation"],"license":"MIT","homepage":"https://github.com/mastergray/type-spec#readme","bugs":{"url":"https://github.com/mastergray/type-spec/issues"},"readme":"# type-spec\n\n`type-spec` is designed to be a lightweight, dynamic type enforcement system for JavaScript. It represents types as object literals with constrained properties, allowing for the definition, instantiation, and validation of custom types with clear structural and behavioral constraints. It ensures properties, once defined, remain consistent and cannot be redefined, upholding dependable type behavior.\n\n**Key Features:**\n- **Type Definition and Instantiation**: Define types using a simple class structure that allows specifying property constraints, default values, and validation rules.\n- **Dynamic Type Checking**: Enforce type constraints at runtime, ensuring that objects adhere to the predefined specifications, with comprehensive error handling for type violations.\n- **Immutability and State Management**: Facilitates creating, updating, and managing instances of types in an immutable fashion, promoting safer and more predictable code.\n- **Type-Spec Operations as Transforms**: Define operations that transform data between types, enabling powerful and flexible data manipulation and transformation capabilities.\n- **Customizable and Extensible**: Easily extend types and integrate custom validation logic to suit complex application needs.\n\n**Use Cases:**\n- Ideal for applications requiring robust state management and type integrity without the overhead of static typing languages.\n- Useful in scenarios where dynamic type checking can prevent common bugs and ensure data consistency across components.\n- Well-suited for React web applications, ensuring state and props adhere to well-defined types, enhancing reliability and maintainability.\n- Beneficial for RESTful APIs to enforce request and response data structures, promoting consistency and reducing errors.\n\n## Examples\n\nHere are some examples of how to use the `TypeSpec` class to define and validate type specifications for different scenarios. These examples help illustrate how to create types, define properties, utilize instances, and define operations effectively.\n\n### Defining a Simple User Type\n\nThis example demonstrates defining a `User` type with properties `username` and `age`, ensuring `username` is a non-empty string and `age` is a positive integer.\n\n```javascript\nimport TypeSpec from 'type-spec';\n\nconst User = new TypeSpec('User')\n    .prop('username', TypeSpec.NONEMPTY_STRING, 'defaultUser')\n    .prop('age', value => TypeSpec.NUMBER(value) && value > 0, 18);\n\n// Creating an instance of User:\ntry {\n    const userInstance = User.create({ username: 'johndoe', age: 30 });\n    console.log('User created:', userInstance);\n} catch (error) {\n    console.error(error.message);\n}\n\n// Attempting to create a user with invalid data:\ntry {\n    const invalidUser = User.create({ username: '', age: -5 });\n} catch (error) {\n    console.error(error.message);  // Outputs error messages for invalid username and age\n}\n```\n\n### Using Subtypes to Extend a Base Type\n\nThis example shows how to extend a base `User` type to define an `Admin` type with an additional `accessLevel` property:\n\n```javascript\nconst Admin = new TypeSpec('Admin', User)\n    .prop('accessLevel', value => TypeSpec.NUMBER(value) && value >= 1, 1);\n\n// Creating an instance of Admin:\ntry {\n    const adminInstance = Admin.create({ username: 'adminuser', age: 34, accessLevel: 3 });\n    console.log('Admin created:', adminInstance);\n} catch (error) {\n    console.error(error.message);\n}\n```\n\n### Enforcing Required Properties\n\nThis example defines a `Book` type where `title` and `author` are required properties, and `year` has a default value:\n\n```javascript\nconst Book = new TypeSpec('Book')\n    .prop('title', TypeSpec.NONEMPTY_STRING)\n    .prop('author', TypeSpec.NONEMPTY_STRING)\n    .prop('year', TypeSpec.NUMBER, 2021);\n\n// Creating a book with all properties provided:\ntry {\n    const bookInstance = Book.create({ title: '1984', author: 'George Orwell', year: 1949 });\n    console.log('Book created:', bookInstance);\n} catch (error) {\n    console.error(error.message);\n}\n\n// Creating a book with default year:\ntry {\n    const bookDefaultYear = Book.create({ title: 'Brave New World', author: 'Aldous Huxley' });\n    console.log('Book created with default year:', bookDefaultYear);\n} catch (error) {\n    console.error(error.message);\n}\n```\n\n### Updating an Instance\n\nThis example updates a `Product` instance, ensuring new properties are validated:\n\n```javascript\nconst Product = new TypeSpec('Product')\n    .prop('name', TypeSpec.NONEMPTY_STRING)\n    .prop('price', value => TypeSpec.NUMBER(value) && value >= 0, 0);\n\n// Creating a product instance:\nlet productInstance = Product.create({ name: 'Laptop', price: 999 });\nconsole.log('Initial product:', productInstance);\n\n// Updating the product's price:\ntry {\n    productInstance = Product.update(productInstance, { price: 1099 });\n    console.log('Updated product:', productInstance);\n} catch (error) {\n    console.error('Error:', error.message);  // Outputs an error message for invalid price\n}\n\n// Attempting to update with invalid data:\ntry {\n    productInstance = Product.update(productInstance, { price: -50 });\n} catch (error) {\n    console.error('Error:', error.message);  // Should output an error message for invalid price\n}\n```\n\n### Defining and Using type-spec Operations\n\nThis example demonstrates how to define and use type-spec operations to transform data between types:\n\n```javascript\nimport TypeSpec, { TypeSpecOp } from 'type-spec';\n\n// Define User type\nconst User = new TypeSpec('User')\n    .prop('username', TypeSpec.NONEMPTY_STRING)\n    .prop('age', value => TypeSpec.NUMBER(value) && value > 0);\n\n// Define UserSummary type\nconst UserSummary = new TypeSpec('UserSummary')\n    .prop('username', TypeSpec.NONEMPTY_STRING)\n    .prop('isAdult', TypeSpec.BOOL);\n\n// Define transformation function\nconst userToSummaryFn = (fromValue) => ({\n    username: fromValue.username,\n    isAdult: fromValue.age >= 18\n});\n\n// Define User to UserSummary operation\nconst userToSummaryOp = new TypeSpecOp(User, UserSummary)\n    .ontoResult('username', 'isAdult', userToSummaryFn);\n\n// Creating an instance of User:\nconst userInstance = User.create({ username: 'johndoe', age: 30 });\nconsole.log('User created:', userInstance);\n\n// Transform User to UserSummary:\ntry {\n    const summaryInstance = userToSummaryOp.run(userInstance);\n    console.log('UserSummary created:', summaryInstance);\n} catch (error) {\n    console.error('Error:', error.message);\n}\n```\n\n### Defining and Using Asynchronous type-spec Operations\n\nThis example demonstrates how to define and use asynchronous type-spec operations to transform data between types:\n\n```javascript\nimport TypeSpec, { TypeSpecAsyncOp } from 'type-spec';\n\n// Define User type\nconst User = new TypeSpec('User')\n    .prop('username', TypeSpec.NONEMPTY_STRING)\n    .prop('age', value => TypeSpec.NUMBER(value) && value > 0);\n\n// Define UserSummary type\nconst UserSummary = new TypeSpec('UserSummary')\n    .prop('username', TypeSpec.NONEMPTY_STRING)\n    .prop('isAdult', TypeSpec.BOOL);\n\n// Define asynchronous transformation function\nconst userToSummaryAsyncFn = async (fromValue) => ({\n    username: fromValue.username,\n    isAdult: fromValue.age >= 18\n});\n\n// Define User to UserSummary asynchronous operation\nconst userToSummaryAsyncOp = new TypeSpecAsyncOp(User, UserSummary)\n    .ontoResult('username', 'isAdult', userToSummaryAsyncFn);\n\n// Creating an instance of User:\nconst userInstance = User.create({ username: 'johndoe', age: 30 });\nconsole.log('User created:', userInstance);\n\n// Transform User to UserSummary:\nuserToSummaryAsyncOp.run(userInstance).then(summaryInstance => {\n    console.log('UserSummary created:', summaryInstance);\n}).catch(error => {\n    console.error('Error:', error.message);\n});\n```\n\n### Defining and Using TypeSpecProc for Composable Operations\n\nThis example demonstrates how to define and use `TypeSpecProc` to compose and run multiple operations:\n\n```javascript\nimport TypeSpec from 'type-spec';\nimport TypeSpecOp from 'type-spec/TypeSpecOp';\nimport TypeSpecProc from 'type-spec/TypeSpecProc';\n\n// Define User type\nconst User = new TypeSpec('User')\n    .prop('username', TypeSpec.NONEMPTY_STRING)\n    .prop('age', value => TypeSpec.NUMBER(value) && value > 0);\n\n// Define UserSummary type\nconst UserSummary = new TypeSpec('UserSummary')\n    .prop('username', TypeSpec.NONEMPTY_STRING)\n    .prop('isAdult', TypeSpec.BOOL);\n\n// Define transformation functions\nconst userToSummaryFn = (fromValue) => ({\n    username: fromValue.username,\n    isAdult: fromValue.age >= 18\n});\nconst addGreetingFn = (fromValue) => ({\n    ...fromValue,\n    greeting: `Hello, ${fromValue.username}`\n});\n\n// Define User to UserSummary operation\nconst userToSummaryOp = new TypeSpecOp(User, UserSummary)\n    .ontoResult('username', 'isAdult', userToSummaryFn);\n\n// Define another operation to add greeting\nconst addGreetingOp = new TypeSpecOp(UserSummary, UserSummary)\n    .ontoResult('username', 'greeting', addGreetingFn);\n\n// Compose operations using TypeSpecProc\nconst proc = new TypeSpecProc();\nproc.op(userToSummaryOp).op(addGreetingOp);\n\n// Creating an instance of\n\n User:\nconst userInstance = User.create({ username: 'johndoe', age: 30 });\nconsole.log('User created:', userInstance);\n\n// Run composed operations:\nproc.run(userInstance).then(finalResult => {\n    console.log('Final result:', finalResult);  // { username: 'johndoe', isAdult: true, greeting: 'Hello, johndoe' }\n}).catch(error => {\n    console.error('Error:', error.message);\n});\n```\n\n### Notes on Composition and Reference\n\nWhen composing operations and procedures using `TypeSpecOp` and `TypeSpecProc`, be aware that operations are stored by reference. This means that changes to the original operation or procedure will impact the composed operation or procedure. If isolation is necessary, consider creating copies of operations before composing.\n\n### Using TypeSpecBuild for Optimized Instances\n\nThis example demonstrates how to use `TypeSpecBuild` to create optimized instances of a `TypeSpec` type for improved performance.\n\n```javascript\nimport TypeSpec from 'type-spec';\nimport TypeSpecBuild from 'type-spec/TypeSpecBuild';\n\n// Define a Product type\nconst Product = new TypeSpec('Product')\n    .prop('name', TypeSpec.NONEMPTY_STRING)\n    .prop('price', value => TypeSpec.NUMBER(value) && value >= 0, 0);\n\n// Create a precomputed version of the Product type\nconst OptimizedProduct = Product.build();\n\n// Creating an optimized product instance:\ntry {\n    const optimizedProductInstance = OptimizedProduct.create({ name: 'Smartphone', price: 699 });\n    console.log('Optimized product created:', optimizedProductInstance);\n} catch (error) {\n    console.error('Error:', error.message);\n}\n\n// Checking if an instance is valid:\ntry {\n    const isValid = OptimizedProduct.isOf({ name: 'Smartphone', price: 699 });\n    console.log('Is valid:', isValid);  // Should output: Is valid: true\n} catch (error) {\n    console.error('Error:', error.message);\n}\n```\n\n## Notice\n\n`type-spec` is very much a work-in-progress. While the base implementation seems stable, I'd like to introduce more robust and automated testing, especially given this project's intent - not to mention I have plenty of benchmarking I want to do too. Documentation is currently in draft as well, since what's currently included was generated by ChatGPT. For better or worse...","readmeFilename":"README.md"}