nytra 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ import "reflect-metadata";
2
+ import { Nytra } from "./Nytra.ts";
3
+ export declare class NytraExperimental {
4
+ private static getMetaData;
5
+ static registerClass(index: number): <T extends Function>(target: T) => void;
6
+ static registerField(position: Parameters<typeof Nytra.registerField>[0], targetTypeId?: Parameters<typeof Nytra.registerField>[1], options?: Parameters<typeof Nytra.registerField>[2]): <T extends object>(target: T, propertyKey: keyof T) => void;
7
+ }
@@ -0,0 +1,54 @@
1
+ import "reflect-metadata";
2
+ import { Nytra } from "./Nytra.js";
3
+ const metaData = new Map();
4
+ export class NytraExperimental {
5
+ static getMetaData(target) {
6
+ let ctx = metaData.get(target);
7
+ if (!ctx) {
8
+ ctx = {};
9
+ metaData.set(target, ctx);
10
+ return ctx;
11
+ }
12
+ return ctx;
13
+ }
14
+ static registerClass(index) {
15
+ const realDecorator = Nytra.registerClass(index);
16
+ return function (target) {
17
+ const meta = NytraExperimental.getMetaData(target);
18
+ realDecorator(target, {
19
+ addInitializer(initializer) {
20
+ }, kind: "class", metadata: meta, name: undefined
21
+ });
22
+ };
23
+ }
24
+ static registerField(position, targetTypeId, options) {
25
+ const realDecorator = Nytra.registerField(position, targetTypeId, options);
26
+ return function (target, propertyKey) {
27
+ let targetClass = target.constructor;
28
+ if (typeof propertyKey !== 'string') {
29
+ throw new Error('propertyKey must be a string');
30
+ }
31
+ const meta = NytraExperimental.getMetaData(targetClass);
32
+ realDecorator(undefined, {
33
+ addInitializer(initializer) {
34
+ },
35
+ kind: "field",
36
+ static: typeof targetClass === 'function',
37
+ name: propertyKey,
38
+ private: propertyKey.startsWith("#"),
39
+ metadata: meta,
40
+ access: {
41
+ has(object) {
42
+ return propertyKey in object;
43
+ },
44
+ set(object, value) {
45
+ object[propertyKey] = value;
46
+ },
47
+ get(object) {
48
+ return object[propertyKey];
49
+ }
50
+ }
51
+ });
52
+ };
53
+ }
54
+ }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { Nytra } from "./Nytra.ts";
2
+ export { NytraExperimental } from "./NytraExperimental.ts";
2
3
  export * as Types from "./Types.ts";
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { Nytra } from "./Nytra.js";
2
+ export { NytraExperimental } from "./NytraExperimental.js";
2
3
  export * as Types from "./Types.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "nytra",
4
- "version": "0.0.7",
4
+ "version": "0.0.8",
5
5
  "description": "A javascript ES6 Decorator driven library to encode/decode javascript objects to/from binary optimized buffers to reduce payload on network",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -30,6 +30,7 @@
30
30
  "devDependencies": {
31
31
  "@msgpack/msgpack": "^3.1.3",
32
32
  "@types/bun": "^1.3.13",
33
+ "reflect-metadata": "^0.2.2",
33
34
  "typescript": "^6.0.3"
34
35
  },
35
36
  "exports": {