{"_id":"@affinity-lab/class-meta-data","_rev":"6-68a02252b988b696d73017f646372fa4","name":"@affinity-lab/class-meta-data","dist-tags":{"latest":"0.0.4"},"versions":{"0.0.1":{"name":"@affinity-lab/class-meta-data","version":"0.0.1","author":{"name":"Affinity Lab"},"main":"dist/index","scripts":{"build":"npx tsc && npm version patch --no-git-tag-version","prebuild":"rimraf ./dist"},"dependencies":{"uni-flatten":"^1.5.5"},"devDependencies":{"rimraf":"^5.0.5","typescript":"^5.2.2"},"_id":"@affinity-lab/class-meta-data@0.0.1","gitHead":"2f34232481a90f68a7d6a4a408e376f5354dd4c1","types":"./dist/index.d.ts","_nodeVersion":"20.5.1","_npmVersion":"9.8.0","dist":{"integrity":"sha512-ODMqfNWpuyYAyom7+Z/eG6UReAzq+GA9//zT8Etuh/PrNCM+Q+2aKM6phsTJDpZkVfsgSywlyRnWUxWvPqIS4Q==","shasum":"9598a25866826d106c13e55a28aa742660d213b1","tarball":"https://registry.npmjs.org/@affinity-lab/class-meta-data/-/class-meta-data-0.0.1.tgz","fileCount":15,"unpackedSize":21442,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQChjphHqIzRHVNe6IT5FL3+uxPnipn7SmoZQ6qk0pWgfwIgPtMmgL27Zdz7YQIRv4YMRZSnLSBd2sRdXmLzcEFg1ts="}]},"_npmUser":{"name":"laborci","email":"gergely@laborci.hu"},"directories":{},"maintainers":[{"name":"laborci","email":"gergely@laborci.hu"},{"name":"affinity-lab-organizer","email":"laborci.gergely+affinity@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/class-meta-data_0.0.1_1706784508036_0.6358750427027904"},"_hasShrinkwrap":false},"0.0.2":{"name":"@affinity-lab/class-meta-data","version":"0.0.2","author":{"name":"Affinity Lab"},"main":"dist/index","scripts":{"build":"npx tsc && npm version patch --no-git-tag-version","prebuild":"rimraf ./dist"},"dependencies":{"uni-flatten":"^1.5.5"},"devDependencies":{"rimraf":"^5.0.5","typescript":"^5.2.2"},"_id":"@affinity-lab/class-meta-data@0.0.2","gitHead":"2f34232481a90f68a7d6a4a408e376f5354dd4c1","types":"./dist/index.d.ts","description":"The ClassMetaData library provides a powerful mechanism for attaching metadata to classes in TypeScript. This metadata can be useful for various purposes such as configuration, annotation, or any other application-specific data associatedb with classes.","_nodeVersion":"20.5.1","_npmVersion":"9.8.0","dist":{"integrity":"sha512-VeXg3SskGfBZ3ySM+0hxcQPu76o1+34plC5TVoKDODAfvAZnxn2NkQHGGZ8uayaNNiAoSSCA6clKcQ59+y7+Fg==","shasum":"e527e401b5400a20e32e913d9f2594bbb2783b88","tarball":"https://registry.npmjs.org/@affinity-lab/class-meta-data/-/class-meta-data-0.0.2.tgz","fileCount":15,"unpackedSize":21442,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICwFndlC7AyPAVDGo0CQWYsA9mZN9r7P/LnER7g9oqupAiEA/AoHVX+EVRQPQgGrvKNnCGjdUAjgjhXWfLqgZq/Mxk0="}]},"_npmUser":{"name":"laborci","email":"gergely@laborci.hu"},"directories":{},"maintainers":[{"name":"laborci","email":"gergely@laborci.hu"},{"name":"affinity-lab-organizer","email":"laborci.gergely+affinity@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/class-meta-data_0.0.2_1706784581824_0.6151846936909224"},"_hasShrinkwrap":false},"0.0.3":{"name":"@affinity-lab/class-meta-data","version":"0.0.3","author":{"name":"Affinity Lab"},"main":"dist/index","scripts":{"build":"npx tsc && npm version patch --no-git-tag-version","prebuild":"rimraf ./dist"},"dependencies":{"uni-flatten":"^1.5.5"},"devDependencies":{"rimraf":"^5.0.5","typescript":"^5.2.2"},"_id":"@affinity-lab/class-meta-data@0.0.3","gitHead":"2f34232481a90f68a7d6a4a408e376f5354dd4c1","types":"./dist/index.d.ts","description":"The ClassMetaData library provides a powerful mechanism for attaching metadata to classes in TypeScript. This metadata can be useful for various purposes such as configuration, annotation, or any other application-specific data associated with classes.","_nodeVersion":"20.5.1","_npmVersion":"9.8.0","dist":{"integrity":"sha512-fk9IoW8BVr9LTmkgkqc691oZwlJ/n7wRDshjp2krw2Dz+CMx+YEeyMad2XHneA2glItAtkdLCld9HIWL9Q4qGQ==","shasum":"20f8fa1e16959b405da92e76b72909565aa34007","tarball":"https://registry.npmjs.org/@affinity-lab/class-meta-data/-/class-meta-data-0.0.3.tgz","fileCount":15,"unpackedSize":21443,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHeHezpNL9bsKydKy1ZXyRVX/o3iqFGLWSsJzWUCjEJMAiEA4vDwgXH8uirijl3hdLanD3lcTzgtpaamfR/MapRzBfc="}]},"_npmUser":{"name":"laborci","email":"gergely@laborci.hu"},"directories":{},"maintainers":[{"name":"laborci","email":"gergely@laborci.hu"},{"name":"affinity-lab-organizer","email":"laborci.gergely+affinity@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/class-meta-data_0.0.3_1706784676142_0.5037920987146238"},"_hasShrinkwrap":false},"0.0.4":{"name":"@affinity-lab/class-meta-data","version":"0.0.4","author":{"name":"Affinity Lab"},"main":"dist/index","scripts":{"build":"npx tsc && npm version patch --no-git-tag-version","prebuild":"rimraf ./dist"},"dependencies":{"uni-flatten":"^1.5.5"},"devDependencies":{"rimraf":"^5.0.5","typescript":"^5.2.2"},"_id":"@affinity-lab/class-meta-data@0.0.4","gitHead":"2f34232481a90f68a7d6a4a408e376f5354dd4c1","types":"./dist/index.d.ts","description":"The ClassMetaData library provides a powerful mechanism for attaching metadata to classes in TypeScript. This metadata can be useful for various purposes such as configuration, annotation, or any other application-specific data associated with classes.","_nodeVersion":"20.5.1","_npmVersion":"9.8.0","dist":{"integrity":"sha512-pG6qoy3NmYgINB9g9X/PaHWYeYXI1uCOVaAGa1xfiMrBteADGpxtecA/DuRvX0Lx/cIXTmCnnHxx2jN85D7R+w==","shasum":"fe1af2c30f58b6e5dfa2ba068fd155182b6b94d4","tarball":"https://registry.npmjs.org/@affinity-lab/class-meta-data/-/class-meta-data-0.0.4.tgz","fileCount":15,"unpackedSize":21422,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDHtQY1WDSHs6Cag6K/JOOeQSyHbi6RWC23ZkLpsBolPAiAllW2fpB/GV7bF0yhu8CKF6eoV3ZlgNKyij8Fi4oTUbw=="}]},"_npmUser":{"name":"laborci","email":"gergely@laborci.hu"},"directories":{},"maintainers":[{"name":"laborci","email":"gergely@laborci.hu"},{"name":"affinity-lab-organizer","email":"laborci.gergely+affinity@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/class-meta-data_0.0.4_1706784760697_0.6220395688081497"},"_hasShrinkwrap":false}},"time":{"created":"2024-02-01T10:48:27.935Z","0.0.1":"2024-02-01T10:48:28.171Z","modified":"2024-04-22T11:55:03.945Z","0.0.2":"2024-02-01T10:49:41.989Z","0.0.3":"2024-02-01T10:51:16.304Z","0.0.4":"2024-02-01T10:52:40.824Z"},"maintainers":[{"email":"szaj.szabolcs@gmail.com","name":"frogyboy"},{"email":"gabberson0312@gmail.com","name":"gabi0312"},{"email":"divad.sari@gmail.com","name":"davdom004"},{"email":"gergely@laborci.hu","name":"laborci"},{"email":"laborci.gergely+affinity@gmail.com","name":"affinity-lab-organizer"}],"author":{"name":"Affinity Lab"},"readme":"# ClassMetaData\n\nThe ClassMetaData library provides a powerful mechanism for attaching metadata to classes in TypeScript. This metadata can be useful for various purposes such as configuration, annotation, or any other application-specific data associated with classes.\n\n## Writing the metadata\n\n### 1. Create an Instance of ClassMetaData:\n\nBegin by creating an instance of the `ClassMetaData` class. This instance will be used to manage and organize metadata\nstores for various classes.\n\n```ts\nconst metaData = new ClassMetaData();\n```\n\n### 2. Access or Create a MetaDataStore:\n\nUse the `get` method to access or create a `MetaDataStore` for the target class. If the store doesn't exist and you want\nto create it, set the create parameter to `true`.\n\n```ts\n// Example class\nclass ExampleClass {\n\t// ... class implementation ...\n}\n\n// Access or create metadata store for ExampleClass\nconst metaDataStore = metaData.get(ExampleClass, true);\n```\n\n### 3. Write Metadata with MetaDataStore:\n\nOnce you have the `MetaDataStore` instance, you can use its methods to write metadata. The `MetaDataStore` provides the following methods:\n\n> `merge(key: string | string[], value: Record<string, any>): void`\n>\n> Merge metadata with existing data.\n\n> `set(key: string | string[], value: any): void`\n>\n> Set a single value for the specified `key`.\n\n> `push(key: string | string[], value: any): void`\n>\n> Push a value to an array associated with the `key`.\n\n> `delete(key: string | string[]): void`\n>\n> Delete metadata associated with the specified `key`.\n\n```ts\n// Set a single metadata value\nmetaDataStore?.set('propertyName', 'propertyValue');\n```\n\n#### Data types\n\nThe data manipulation methods: `set`, `push`, and `merge` are provided by the ClassMetaData library for writing metadata. These methods play a pivotal role in shaping the structure of metadata associated with TypeScript classes, offering flexibility in handling single values, arrays, and complex nested properties.\n\n##### 1. set: Setting a Single Value\nThe `set` method in the `ClassMetaData` library is used to set a single value for a specific key or property. This method is suitable when you want to assign a straightforward, standalone value to a metadata property. It overwrites any existing data associated with the specified key, ensuring that only the most recent value is retained.\n\n```ts\n// Setting a single value for a metadata property\nmetaDataStore.set('propertyName', 'propertyValue');\n```\n\n##### 2. push: Adding to an Array\nThe `push` method is employed when dealing with properties that hold an array of values. It appends a new value to the existing array associated with the specified key. This is particularly useful when multiple values need to be associated with the same property, creating an array of metadata for a given key.\n\n```ts\n// Adding a value to an array property in metadata\nmetaDataStore.push('arrayProperty', 'arrayValue1');\nmetaDataStore.push('arrayProperty', 'arrayValue2');\n```\n\n##### 3. merge: Merging with Existing Data\nThe merge method allows for combining new metadata with existing data. It is especially useful when dealing with nested properties or complex metadata structures. The merge operation ensures that the existing metadata is preserved while incorporating the new values. This method is versatile, accommodating various data structures and enabling the creation of intricate metadata hierarchies.\n\n```ts\n// Merging metadata with existing data for nested properties\nmetaDataStore.merge('nested.property.subProperty', 'subValue1');\nmetaDataStore.merge(['nested', 'property', 'subProperty'], 'subValue2');\n```\n\n##### Consistency Note:\nIt's important to note that maintaining consistency in the choice of method (`set`, `push`, or `merge`) when interacting with the same property or key is crucial. Using the same method ensures a standardized approach, avoiding confusion and enhancing code readability when managing metadata for a particular class. Choose the method that aligns with the nature of the metadata and the desired structure for a more organized and maintainable codebase.\n\n#### Flexible Nesting with Dot Notation or String Arrays\n\nThe `ClassMetaData` library provides flexibility in how you define and handle nested properties within your metadata. This section outlines two approaches: using dot notation on the key and passing a string array as the key argument.\n\n##### 1. Dot Notation for Nesting\n\nThe dot notation is a concise and expressive way to represent nested properties within your metadata. When using dot notation, each dot represents a level of nesting. The `merge` method is designed to work seamlessly with dot notation, making it intuitive to create and manage nested properties.\n\n```ts\n// Using dot notation for nesting\nmetaDataStore?.merge('nested.property.subProperty', 'subValue');\n```\n\n##### 2. String Array as Key Argument\nAlternatively, you can use a string array to represent the hierarchy of nested properties. Each element in the array corresponds to a level of nesting. This approach is particularly useful when the nesting structure is dynamic or when the nesting levels are determined at runtime.\n\n```ts\n// Using string array as the key argument for nesting\nmetaDataStore.merge(['nested', 'property', 'subProperty'], 'subValue');\n```\n## Reading Metadata in ClassMetaData\n\nOnce metadata has been set using the `ClassMetaData` library, retrieving and interpreting this information is vital for leveraging the associated values. \n\nTo retrieve metadata for a specific class, use the `read` method of the ClassMetaData class. \n\n```ts\n// Reading metadata for ExampleClass\nconst metadataResult = metaData.read(ExampleClass);\nconsole.log(metadataResult);\n```\n\nThe read method's second optional argument is an options object with two properties:\n\n- `flatten` (boolean, default: `false`): If set to `true`, the return will be a \"flattened\" object, where sub keys are separated by dots (dot-notation) according to their specification. If the value is `false`, the response will maintain a regular object hierarchy.\n\n- `simplify` (boolean, default: `true`): If set to `true`, the response will include only the most relevant data based on inheritance rules. If set to `false`, the response will include all data generated during the inheritance process.\n\n```ts\n// Reading metadata for ExampleClass\nconst metadataResult = metaData.read(ExampleClass, {flatten: false, simplify: true});\nconsole.log(metadataResult);\n```\n\n### Results with inheritance (`{simplify:false}`)\n\nIf the examined object is part of an inheritance chain, the system also unfolds the metadata generated during inheritance.\n\nWhen the `simplify` option is set to `false`, the return of the read method will be an `MetaValue` object with the following properties:\n\n- `value`: The most recently set value during inheritance.\n- `self`: The value present in the requested class.\n- `inherited`: An array containing values set in the order of the inheritance chain.\n\nThis structure provides comprehensive information about the values associated with the class, both inherited and self-defined.","readmeFilename":"README.md","description":"The ClassMetaData library provides a powerful mechanism for attaching metadata to classes in TypeScript. This metadata can be useful for various purposes such as configuration, annotation, or any other application-specific data associated with classes."}