@xyo-network/payload-model 2.110.10 → 2.110.12
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.
- package/dist/browser/Schema.d.cts +2 -2
- package/dist/browser/Schema.d.cts.map +1 -1
- package/dist/browser/Schema.d.mts +2 -2
- package/dist/browser/Schema.d.mts.map +1 -1
- package/dist/browser/Schema.d.ts +2 -2
- package/dist/browser/Schema.d.ts.map +1 -1
- package/dist/browser/index.cjs +22 -26
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +22 -28
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/isPayload.d.cts +4 -4
- package/dist/browser/isPayload.d.cts.map +1 -1
- package/dist/browser/isPayload.d.mts +4 -4
- package/dist/browser/isPayload.d.mts.map +1 -1
- package/dist/browser/isPayload.d.ts +4 -4
- package/dist/browser/isPayload.d.ts.map +1 -1
- package/dist/neutral/Schema.d.cts +2 -2
- package/dist/neutral/Schema.d.cts.map +1 -1
- package/dist/neutral/Schema.d.mts +2 -2
- package/dist/neutral/Schema.d.mts.map +1 -1
- package/dist/neutral/Schema.d.ts +2 -2
- package/dist/neutral/Schema.d.ts.map +1 -1
- package/dist/neutral/index.cjs +22 -26
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +22 -28
- package/dist/neutral/index.js.map +1 -1
- package/dist/neutral/isPayload.d.cts +4 -4
- package/dist/neutral/isPayload.d.cts.map +1 -1
- package/dist/neutral/isPayload.d.mts +4 -4
- package/dist/neutral/isPayload.d.mts.map +1 -1
- package/dist/neutral/isPayload.d.ts +4 -4
- package/dist/neutral/isPayload.d.ts.map +1 -1
- package/dist/node/Schema.d.cts +2 -2
- package/dist/node/Schema.d.cts.map +1 -1
- package/dist/node/Schema.d.mts +2 -2
- package/dist/node/Schema.d.mts.map +1 -1
- package/dist/node/Schema.d.ts +2 -2
- package/dist/node/Schema.d.ts.map +1 -1
- package/dist/node/index.cjs +22 -26
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +22 -28
- package/dist/node/index.js.map +1 -1
- package/dist/node/isPayload.d.cts +4 -4
- package/dist/node/isPayload.d.cts.map +1 -1
- package/dist/node/isPayload.d.mts +4 -4
- package/dist/node/isPayload.d.mts.map +1 -1
- package/dist/node/isPayload.d.ts +4 -4
- package/dist/node/isPayload.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/Schema.ts +1 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/Meta.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["export * from './Error.js'\nexport * from './isPayload.js'\nexport * from './isPayloadOfSchemaType.js'\nexport * from './isPayloadWithHash.js'\nexport * from './Meta.js'\nexport * from './Payload.js'\nexport * from './PayloadFindFilter.js'\nexport * from './PayloadSet/index.js'\nexport * from './PayloadValidationFunction.js'\nexport * from './PayloadValueExpression.js'\nexport * from './Query.js'\nexport * from './Schema.js'\n","import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload.js'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload =\n <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.js'\nimport { WithMeta } from './Meta.js'\nimport { Payload, WithSources } from './Payload.js'\n\nexport const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithMeta = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithMeta<T> => isPayloadOfSchemaType<WithMeta<T>>(schema)(x) && x.$hash !== undefined\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n//test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\nconst testWithMeta: WithMeta<Test> = { $hash: '1234abcd', $meta: { timestamp: Date.now() }, field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\nconst testMetaPayloads: WithMeta<Payload>[] = [testWithMeta]\n\nconst testType: Test = testWithMeta\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMeta: Payload[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMetaWithMeta: PayloadWithMeta[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n\nconst isTestFromMetaTypedWithMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestWithMeta: WithMeta<Test>[] = testPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\nconst isTestWithMetaFromMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\n*/\n","import { Hash } from '@xylabs/hex'\nimport { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.js'\nimport { Payload } from './Payload.js'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload.js'\nimport { WithMeta } from './Meta.js'\nimport { Payload } from './Payload.js'\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isWithHash = <T extends Payload>(value: T): value is WithMeta<T> => {\n return typeof (value as WithMeta<T>)?.$hash === 'string'\n}\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isPayloadWithHash = <T extends Payload>(value: unknown): value is WithMeta<T> => {\n return isAnyPayload(value) && isWithHash(value)\n}\n","import { EmptyObject, JsonObject } from '@xylabs/object'\n\nimport { Payload, PayloadMetaFields } from './Payload.js'\nimport { Schema, WithSchema } from './Schema.js'\n\nexport type WithMeta<T extends Payload = Payload, M extends JsonObject | void = void> = PayloadMetaFields<M> & T\nexport type WithOptionalMeta<T extends Payload = Payload, M extends JsonObject | void = void> = Partial<WithMeta<T, M>> &\n Omit<WithMeta<T, M>, '$hash'>\n\nexport type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>\n\nexport const unMeta = <T extends WithMeta<Payload>>(payload?: T): T | undefined => {\n if (payload) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { $meta, $hash, ...result } = payload\n return result as T\n }\n}\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import { AsTypeFactory, EmptyObject } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/Meta.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["export * from './Error.js'\nexport * from './isPayload.js'\nexport * from './isPayloadOfSchemaType.js'\nexport * from './isPayloadWithHash.js'\nexport * from './Meta.js'\nexport * from './Payload.js'\nexport * from './PayloadFindFilter.js'\nexport * from './PayloadSet/index.js'\nexport * from './PayloadValidationFunction.js'\nexport * from './PayloadValueExpression.js'\nexport * from './Query.js'\nexport * from './Schema.js'\n","import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload.js'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload =\n <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.js'\nimport { WithMeta } from './Meta.js'\nimport { Payload, WithSources } from './Payload.js'\n\nexport const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithMeta = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithMeta<T> => isPayloadOfSchemaType<WithMeta<T>>(schema)(x) && x.$hash !== undefined\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n//test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\nconst testWithMeta: WithMeta<Test> = { $hash: '1234abcd', $meta: { timestamp: Date.now() }, field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\nconst testMetaPayloads: WithMeta<Payload>[] = [testWithMeta]\n\nconst testType: Test = testWithMeta\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMeta: Payload[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMetaWithMeta: PayloadWithMeta[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n\nconst isTestFromMetaTypedWithMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestWithMeta: WithMeta<Test>[] = testPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\nconst isTestWithMetaFromMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\n*/\n","import { Hash } from '@xylabs/hex'\nimport { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.js'\nimport { Payload } from './Payload.js'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload.js'\nimport { WithMeta } from './Meta.js'\nimport { Payload } from './Payload.js'\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isWithHash = <T extends Payload>(value: T): value is WithMeta<T> => {\n return typeof (value as WithMeta<T>)?.$hash === 'string'\n}\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isPayloadWithHash = <T extends Payload>(value: unknown): value is WithMeta<T> => {\n return isAnyPayload(value) && isWithHash(value)\n}\n","import { EmptyObject, JsonObject } from '@xylabs/object'\n\nimport { Payload, PayloadMetaFields } from './Payload.js'\nimport { Schema, WithSchema } from './Schema.js'\n\nexport type WithMeta<T extends Payload = Payload, M extends JsonObject | void = void> = PayloadMetaFields<M> & T\nexport type WithOptionalMeta<T extends Payload = Payload, M extends JsonObject | void = void> = Partial<WithMeta<T, M>> &\n Omit<WithMeta<T, M>, '$hash'>\n\nexport type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>\n\nexport const unMeta = <T extends WithMeta<Payload>>(payload?: T): T | undefined => {\n if (payload) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { $meta, $hash, ...result } = payload\n return result as T\n }\n}\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import { AsTypeFactory, EmptyObject } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAA0C;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,UAAI,wBAAS,KAAK,GAAG;AACnB,WAAO,OAAO,MAAM,WAAW;AAAA,EACjC;AACA,SAAO;AACT;AAEO,IAAM,eAAe,8BAAgB,OAAO,YAAY;AAExD,IAAM,YACX,CAAoB,WACpB,CAAC,UAA+B;AAC9B,MAAI,aAAa,KAAK,GAAG;AACvB,WAAO,OAAO,SAAS,MAAM,MAAM;AAAA,EACrC;AACA,SAAO;AACT;AAEK,IAAM,YAAY,CAAoB,WAAqB,8BAAgB,OAAO,CAAC,UAA+B,UAAU,MAAM,EAAE,KAAK,CAAC;;;AClB1I,IAAM,wBAAwB,CAAoB,WAAmB;AAC1E,SAAO,CAAC,MAA+B,aAAa,CAAC,KAAK,GAAG,WAAW;AAC1E;AAEO,IAAM,gCAAgC,CAAoB,WAAmB;AAClF,SAAO,CAAC,MAAyC,sBAAmC,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU;AAChH;AAEO,IAAM,mCAAmC,CAAoB,WAAmB;AACrF,SAAO,CAAC,MACN,sBAAsC,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,UAAa,MAAM,QAAQ,EAAE,OAAO;AAC1G;AAEO,IAAM,yBAAyB,CAAoB,WAAmB;AAC3E,SAAO,CAAC,MAA+B,CAAC,aAAa,CAAC,KAAK,GAAG,WAAW;AAC3E;;;ACZO,IAAM,oBAAuC;AAW7C,IAAM,gBAAgB,sBAAmC,iBAAiB;;;ACT1E,IAAM,aAAa,CAAoB,UAAmC;AAC/E,SAAO,OAAQ,OAAuB,UAAU;AAClD;AAOO,IAAM,oBAAoB,CAAoB,UAAyC;AAC5F,SAAO,aAAa,KAAK,KAAK,WAAW,KAAK;AAChD;;;ACTO,IAAM,SAAS,CAA8B,YAA+B;AACjF,MAAI,SAAS;AAEX,UAAM,EAAE,OAAO,OAAO,GAAG,OAAO,IAAI;AACpC,WAAO;AAAA,EACT;AACF;;;AChBO,IAAM,mBAAqC;;;ACDlD,IAAAA,iBAA2C;AAKpC,IAAM,gBAAgB;AAGtB,IAAM,WAAW,CAAC,UAAoC;AAC3D,SAAO,OAAO,UAAU;AAC1B;AAEO,IAAM,WAAW,6BAAc,OAAe,QAAQ;","names":["import_object"]}
|
package/dist/neutral/index.js
CHANGED
|
@@ -1,56 +1,53 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/isPayload.ts
|
|
5
2
|
import { AsObjectFactory, isObject } from "@xylabs/object";
|
|
6
|
-
var isAnyPayload =
|
|
3
|
+
var isAnyPayload = (value) => {
|
|
7
4
|
if (isObject(value)) {
|
|
8
5
|
return typeof value.schema === "string";
|
|
9
6
|
}
|
|
10
7
|
return false;
|
|
11
|
-
}
|
|
8
|
+
};
|
|
12
9
|
var asAnyPayload = AsObjectFactory.create(isAnyPayload);
|
|
13
|
-
var isPayload =
|
|
10
|
+
var isPayload = (schema) => (value) => {
|
|
14
11
|
if (isAnyPayload(value)) {
|
|
15
12
|
return schema.includes(value.schema);
|
|
16
13
|
}
|
|
17
14
|
return false;
|
|
18
|
-
}
|
|
19
|
-
var asPayload =
|
|
15
|
+
};
|
|
16
|
+
var asPayload = (schema) => AsObjectFactory.create((value) => isPayload(schema)(value));
|
|
20
17
|
|
|
21
18
|
// src/isPayloadOfSchemaType.ts
|
|
22
|
-
var isPayloadOfSchemaType =
|
|
19
|
+
var isPayloadOfSchemaType = (schema) => {
|
|
23
20
|
return (x) => isAnyPayload(x) && x?.schema === schema;
|
|
24
|
-
}
|
|
25
|
-
var isPayloadOfSchemaTypeWithMeta =
|
|
21
|
+
};
|
|
22
|
+
var isPayloadOfSchemaTypeWithMeta = (schema) => {
|
|
26
23
|
return (x) => isPayloadOfSchemaType(schema)(x) && x.$hash !== void 0;
|
|
27
|
-
}
|
|
28
|
-
var isPayloadOfSchemaTypeWithSources =
|
|
24
|
+
};
|
|
25
|
+
var isPayloadOfSchemaTypeWithSources = (schema) => {
|
|
29
26
|
return (x) => isPayloadOfSchemaType(schema)(x) && x.sources !== void 0 && Array.isArray(x.sources);
|
|
30
|
-
}
|
|
31
|
-
var notPayloadOfSchemaType =
|
|
27
|
+
};
|
|
28
|
+
var notPayloadOfSchemaType = (schema) => {
|
|
32
29
|
return (x) => !isAnyPayload(x) || x?.schema !== schema;
|
|
33
|
-
}
|
|
30
|
+
};
|
|
34
31
|
|
|
35
32
|
// src/Error.ts
|
|
36
33
|
var ModuleErrorSchema = "network.xyo.error.module";
|
|
37
34
|
var isModuleError = isPayloadOfSchemaType(ModuleErrorSchema);
|
|
38
35
|
|
|
39
36
|
// src/isPayloadWithHash.ts
|
|
40
|
-
var isWithHash =
|
|
37
|
+
var isWithHash = (value) => {
|
|
41
38
|
return typeof value?.$hash === "string";
|
|
42
|
-
}
|
|
43
|
-
var isPayloadWithHash =
|
|
39
|
+
};
|
|
40
|
+
var isPayloadWithHash = (value) => {
|
|
44
41
|
return isAnyPayload(value) && isWithHash(value);
|
|
45
|
-
}
|
|
42
|
+
};
|
|
46
43
|
|
|
47
44
|
// src/Meta.ts
|
|
48
|
-
var unMeta =
|
|
45
|
+
var unMeta = (payload) => {
|
|
49
46
|
if (payload) {
|
|
50
47
|
const { $meta, $hash, ...result } = payload;
|
|
51
48
|
return result;
|
|
52
49
|
}
|
|
53
|
-
}
|
|
50
|
+
};
|
|
54
51
|
|
|
55
52
|
// src/PayloadSet/PayloadSetSchema.ts
|
|
56
53
|
var PayloadSetSchema = "network.xyo.payload.set";
|
|
@@ -58,12 +55,9 @@ var PayloadSetSchema = "network.xyo.payload.set";
|
|
|
58
55
|
// src/Schema.ts
|
|
59
56
|
import { AsTypeFactory } from "@xylabs/object";
|
|
60
57
|
var PayloadSchema = "network.xyo.payload";
|
|
61
|
-
var isSchema =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
return false;
|
|
66
|
-
}, "isSchema");
|
|
58
|
+
var isSchema = (value) => {
|
|
59
|
+
return typeof value === "string";
|
|
60
|
+
};
|
|
67
61
|
var asSchema = AsTypeFactory.create(isSchema);
|
|
68
62
|
export {
|
|
69
63
|
ModuleErrorSchema,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/Meta.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload.js'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload =\n <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.js'\nimport { WithMeta } from './Meta.js'\nimport { Payload, WithSources } from './Payload.js'\n\nexport const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithMeta = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithMeta<T> => isPayloadOfSchemaType<WithMeta<T>>(schema)(x) && x.$hash !== undefined\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n//test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\nconst testWithMeta: WithMeta<Test> = { $hash: '1234abcd', $meta: { timestamp: Date.now() }, field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\nconst testMetaPayloads: WithMeta<Payload>[] = [testWithMeta]\n\nconst testType: Test = testWithMeta\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMeta: Payload[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMetaWithMeta: PayloadWithMeta[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n\nconst isTestFromMetaTypedWithMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestWithMeta: WithMeta<Test>[] = testPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\nconst isTestWithMetaFromMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\n*/\n","import { Hash } from '@xylabs/hex'\nimport { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.js'\nimport { Payload } from './Payload.js'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload.js'\nimport { WithMeta } from './Meta.js'\nimport { Payload } from './Payload.js'\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isWithHash = <T extends Payload>(value: T): value is WithMeta<T> => {\n return typeof (value as WithMeta<T>)?.$hash === 'string'\n}\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isPayloadWithHash = <T extends Payload>(value: unknown): value is WithMeta<T> => {\n return isAnyPayload(value) && isWithHash(value)\n}\n","import { EmptyObject, JsonObject } from '@xylabs/object'\n\nimport { Payload, PayloadMetaFields } from './Payload.js'\nimport { Schema, WithSchema } from './Schema.js'\n\nexport type WithMeta<T extends Payload = Payload, M extends JsonObject | void = void> = PayloadMetaFields<M> & T\nexport type WithOptionalMeta<T extends Payload = Payload, M extends JsonObject | void = void> = Partial<WithMeta<T, M>> &\n Omit<WithMeta<T, M>, '$hash'>\n\nexport type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>\n\nexport const unMeta = <T extends WithMeta<Payload>>(payload?: T): T | undefined => {\n if (payload) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { $meta, $hash, ...result } = payload\n return result as T\n }\n}\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import { AsTypeFactory, EmptyObject } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n
|
|
1
|
+
{"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/Meta.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload.js'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload =\n <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.js'\nimport { WithMeta } from './Meta.js'\nimport { Payload, WithSources } from './Payload.js'\n\nexport const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithMeta = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithMeta<T> => isPayloadOfSchemaType<WithMeta<T>>(schema)(x) && x.$hash !== undefined\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n//test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\nconst testWithMeta: WithMeta<Test> = { $hash: '1234abcd', $meta: { timestamp: Date.now() }, field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\nconst testMetaPayloads: WithMeta<Payload>[] = [testWithMeta]\n\nconst testType: Test = testWithMeta\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMeta: Payload[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMetaWithMeta: PayloadWithMeta[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n\nconst isTestFromMetaTypedWithMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestWithMeta: WithMeta<Test>[] = testPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\nconst isTestWithMetaFromMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\n*/\n","import { Hash } from '@xylabs/hex'\nimport { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.js'\nimport { Payload } from './Payload.js'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload.js'\nimport { WithMeta } from './Meta.js'\nimport { Payload } from './Payload.js'\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isWithHash = <T extends Payload>(value: T): value is WithMeta<T> => {\n return typeof (value as WithMeta<T>)?.$hash === 'string'\n}\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isPayloadWithHash = <T extends Payload>(value: unknown): value is WithMeta<T> => {\n return isAnyPayload(value) && isWithHash(value)\n}\n","import { EmptyObject, JsonObject } from '@xylabs/object'\n\nimport { Payload, PayloadMetaFields } from './Payload.js'\nimport { Schema, WithSchema } from './Schema.js'\n\nexport type WithMeta<T extends Payload = Payload, M extends JsonObject | void = void> = PayloadMetaFields<M> & T\nexport type WithOptionalMeta<T extends Payload = Payload, M extends JsonObject | void = void> = Partial<WithMeta<T, M>> &\n Omit<WithMeta<T, M>, '$hash'>\n\nexport type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>\n\nexport const unMeta = <T extends WithMeta<Payload>>(payload?: T): T | undefined => {\n if (payload) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { $meta, $hash, ...result } = payload\n return result as T\n }\n}\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import { AsTypeFactory, EmptyObject } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,OAAO,MAAM,WAAW;AAAA,EACjC;AACA,SAAO;AACT;AAEO,IAAM,eAAe,gBAAgB,OAAO,YAAY;AAExD,IAAM,YACX,CAAoB,WACpB,CAAC,UAA+B;AAC9B,MAAI,aAAa,KAAK,GAAG;AACvB,WAAO,OAAO,SAAS,MAAM,MAAM;AAAA,EACrC;AACA,SAAO;AACT;AAEK,IAAM,YAAY,CAAoB,WAAqB,gBAAgB,OAAO,CAAC,UAA+B,UAAU,MAAM,EAAE,KAAK,CAAC;;;AClB1I,IAAM,wBAAwB,CAAoB,WAAmB;AAC1E,SAAO,CAAC,MAA+B,aAAa,CAAC,KAAK,GAAG,WAAW;AAC1E;AAEO,IAAM,gCAAgC,CAAoB,WAAmB;AAClF,SAAO,CAAC,MAAyC,sBAAmC,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU;AAChH;AAEO,IAAM,mCAAmC,CAAoB,WAAmB;AACrF,SAAO,CAAC,MACN,sBAAsC,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,UAAa,MAAM,QAAQ,EAAE,OAAO;AAC1G;AAEO,IAAM,yBAAyB,CAAoB,WAAmB;AAC3E,SAAO,CAAC,MAA+B,CAAC,aAAa,CAAC,KAAK,GAAG,WAAW;AAC3E;;;ACZO,IAAM,oBAAuC;AAW7C,IAAM,gBAAgB,sBAAmC,iBAAiB;;;ACT1E,IAAM,aAAa,CAAoB,UAAmC;AAC/E,SAAO,OAAQ,OAAuB,UAAU;AAClD;AAOO,IAAM,oBAAoB,CAAoB,UAAyC;AAC5F,SAAO,aAAa,KAAK,KAAK,WAAW,KAAK;AAChD;;;ACTO,IAAM,SAAS,CAA8B,YAA+B;AACjF,MAAI,SAAS;AAEX,UAAM,EAAE,OAAO,OAAO,GAAG,OAAO,IAAI;AACpC,WAAO;AAAA,EACT;AACF;;;AChBO,IAAM,mBAAqC;;;ACDlD,SAAS,qBAAkC;AAKpC,IAAM,gBAAgB;AAGtB,IAAM,WAAW,CAAC,UAAoC;AAC3D,SAAO,OAAO,UAAU;AAC1B;AAEO,IAAM,WAAW,cAAc,OAAe,QAAQ;","names":[]}
|
|
@@ -3,16 +3,16 @@ export declare const isAnyPayload: (value: unknown) => value is Payload;
|
|
|
3
3
|
export declare const asAnyPayload: {
|
|
4
4
|
<TType extends {
|
|
5
5
|
schema: string;
|
|
6
|
-
} & import("./Payload.js").PayloadFields>(value: import("
|
|
6
|
+
} & import("./Payload.js").PayloadFields>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
7
7
|
<TType extends {
|
|
8
8
|
schema: string;
|
|
9
|
-
} & import("./Payload.js").PayloadFields>(value: import("
|
|
9
|
+
} & import("./Payload.js").PayloadFields>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<{
|
|
10
10
|
schema: string;
|
|
11
11
|
} & import("./Payload.js").PayloadFields>, config?: import("@xylabs/object").TypeCheckConfig): TType;
|
|
12
12
|
};
|
|
13
13
|
export declare const isPayload: <T extends Payload>(schema: string[]) => (value: unknown) => value is T;
|
|
14
14
|
export declare const asPayload: <T extends Payload>(schema: string[]) => {
|
|
15
|
-
<TType extends T>(value: import("
|
|
16
|
-
<TType extends T>(value: import("
|
|
15
|
+
<TType extends T>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
16
|
+
<TType extends T>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
|
|
17
17
|
};
|
|
18
18
|
//# sourceMappingURL=isPayload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPayload.d.ts","sourceRoot":"","sources":["../../src/isPayload.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,KAAK,IAAI,OAKtD,CAAA;AAED,eAAO,MAAM,YAAY;;;4DAHvB,
|
|
1
|
+
{"version":3,"file":"isPayload.d.ts","sourceRoot":"","sources":["../../src/isPayload.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,KAAK,IAAI,OAKtD,CAAA;AAED,eAAO,MAAM,YAAY;;;4DAHvB,qDAEF,iCACgC,gBAAoB;;;4DAGZ,qDAC1B;;+DAGV,gBACU;CARkD,CAAA;AAEhE,eAAO,MAAM,SAAS,GACnB,CAAC,SAAS,OAAO,UAAU,MAAM,EAAE,aAC5B,OAAO,KAAG,KAAK,IAAI,CAK1B,CAAA;AAEH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,OAAO,UAAU,MAAM,EAAE;oCAd3D,qDAEF,iCACgC,gBAAoB;oCAGZ,qDAC1B,4FAGV,gBACU;CAGoI,CAAA"}
|
|
@@ -3,16 +3,16 @@ export declare const isAnyPayload: (value: unknown) => value is Payload;
|
|
|
3
3
|
export declare const asAnyPayload: {
|
|
4
4
|
<TType extends {
|
|
5
5
|
schema: string;
|
|
6
|
-
} & import("./Payload.js").PayloadFields>(value: import("
|
|
6
|
+
} & import("./Payload.js").PayloadFields>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
7
7
|
<TType extends {
|
|
8
8
|
schema: string;
|
|
9
|
-
} & import("./Payload.js").PayloadFields>(value: import("
|
|
9
|
+
} & import("./Payload.js").PayloadFields>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<{
|
|
10
10
|
schema: string;
|
|
11
11
|
} & import("./Payload.js").PayloadFields>, config?: import("@xylabs/object").TypeCheckConfig): TType;
|
|
12
12
|
};
|
|
13
13
|
export declare const isPayload: <T extends Payload>(schema: string[]) => (value: unknown) => value is T;
|
|
14
14
|
export declare const asPayload: <T extends Payload>(schema: string[]) => {
|
|
15
|
-
<TType extends T>(value: import("
|
|
16
|
-
<TType extends T>(value: import("
|
|
15
|
+
<TType extends T>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
16
|
+
<TType extends T>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
|
|
17
17
|
};
|
|
18
18
|
//# sourceMappingURL=isPayload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPayload.d.ts","sourceRoot":"","sources":["../../src/isPayload.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,KAAK,IAAI,OAKtD,CAAA;AAED,eAAO,MAAM,YAAY;;;4DAHvB,
|
|
1
|
+
{"version":3,"file":"isPayload.d.ts","sourceRoot":"","sources":["../../src/isPayload.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,KAAK,IAAI,OAKtD,CAAA;AAED,eAAO,MAAM,YAAY;;;4DAHvB,qDAEF,iCACgC,gBAAoB;;;4DAGZ,qDAC1B;;+DAGV,gBACU;CARkD,CAAA;AAEhE,eAAO,MAAM,SAAS,GACnB,CAAC,SAAS,OAAO,UAAU,MAAM,EAAE,aAC5B,OAAO,KAAG,KAAK,IAAI,CAK1B,CAAA;AAEH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,OAAO,UAAU,MAAM,EAAE;oCAd3D,qDAEF,iCACgC,gBAAoB;oCAGZ,qDAC1B,4FAGV,gBACU;CAGoI,CAAA"}
|
|
@@ -3,16 +3,16 @@ export declare const isAnyPayload: (value: unknown) => value is Payload;
|
|
|
3
3
|
export declare const asAnyPayload: {
|
|
4
4
|
<TType extends {
|
|
5
5
|
schema: string;
|
|
6
|
-
} & import("./Payload.js").PayloadFields>(value: import("
|
|
6
|
+
} & import("./Payload.js").PayloadFields>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
7
7
|
<TType extends {
|
|
8
8
|
schema: string;
|
|
9
|
-
} & import("./Payload.js").PayloadFields>(value: import("
|
|
9
|
+
} & import("./Payload.js").PayloadFields>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<{
|
|
10
10
|
schema: string;
|
|
11
11
|
} & import("./Payload.js").PayloadFields>, config?: import("@xylabs/object").TypeCheckConfig): TType;
|
|
12
12
|
};
|
|
13
13
|
export declare const isPayload: <T extends Payload>(schema: string[]) => (value: unknown) => value is T;
|
|
14
14
|
export declare const asPayload: <T extends Payload>(schema: string[]) => {
|
|
15
|
-
<TType extends T>(value: import("
|
|
16
|
-
<TType extends T>(value: import("
|
|
15
|
+
<TType extends T>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
16
|
+
<TType extends T>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
|
|
17
17
|
};
|
|
18
18
|
//# sourceMappingURL=isPayload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPayload.d.ts","sourceRoot":"","sources":["../../src/isPayload.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,KAAK,IAAI,OAKtD,CAAA;AAED,eAAO,MAAM,YAAY;;;4DAHvB,
|
|
1
|
+
{"version":3,"file":"isPayload.d.ts","sourceRoot":"","sources":["../../src/isPayload.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,KAAK,IAAI,OAKtD,CAAA;AAED,eAAO,MAAM,YAAY;;;4DAHvB,qDAEF,iCACgC,gBAAoB;;;4DAGZ,qDAC1B;;+DAGV,gBACU;CARkD,CAAA;AAEhE,eAAO,MAAM,SAAS,GACnB,CAAC,SAAS,OAAO,UAAU,MAAM,EAAE,aAC5B,OAAO,KAAG,KAAK,IAAI,CAK1B,CAAA;AAEH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,OAAO,UAAU,MAAM,EAAE;oCAd3D,qDAEF,iCACgC,gBAAoB;oCAGZ,qDAC1B,4FAGV,gBACU;CAGoI,CAAA"}
|
package/dist/node/Schema.d.cts
CHANGED
|
@@ -4,8 +4,8 @@ export declare const PayloadSchema: "network.xyo.payload";
|
|
|
4
4
|
export type PayloadSchema = typeof PayloadSchema;
|
|
5
5
|
export declare const isSchema: (value: unknown) => value is Schema;
|
|
6
6
|
export declare const asSchema: {
|
|
7
|
-
<TType extends string>(value: import("
|
|
8
|
-
<TType extends string>(value: import("
|
|
7
|
+
<TType extends string>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
8
|
+
<TType extends string>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<string>, config?: import("@xylabs/object").TypeCheckConfig): TType;
|
|
9
9
|
};
|
|
10
10
|
export interface SchemaFields extends EmptyObject {
|
|
11
11
|
schema: Schema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAG3D,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,aAAa,uBAAiC,CAAA;AAC3D,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAA;AAEhD,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAG3D,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,aAAa,uBAAiC,CAAA;AAC3D,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAA;AAEhD,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,KAAK,IAAI,MAElD,CAAA;AAED,eAAO,MAAM,QAAQ;;;CAAyC,CAAA;AAG9D,MAAM,WAAW,YAAa,SAAQ,WAAW;IAE/C,MAAM,EAAE,MAAM,CAAA;CACf;AAGD,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,WAAW,GAAG,YAAY,GAAG,CAAC,GAAG,YAAY,CAAA"}
|
package/dist/node/Schema.d.mts
CHANGED
|
@@ -4,8 +4,8 @@ export declare const PayloadSchema: "network.xyo.payload";
|
|
|
4
4
|
export type PayloadSchema = typeof PayloadSchema;
|
|
5
5
|
export declare const isSchema: (value: unknown) => value is Schema;
|
|
6
6
|
export declare const asSchema: {
|
|
7
|
-
<TType extends string>(value: import("
|
|
8
|
-
<TType extends string>(value: import("
|
|
7
|
+
<TType extends string>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
8
|
+
<TType extends string>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<string>, config?: import("@xylabs/object").TypeCheckConfig): TType;
|
|
9
9
|
};
|
|
10
10
|
export interface SchemaFields extends EmptyObject {
|
|
11
11
|
schema: Schema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAG3D,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,aAAa,uBAAiC,CAAA;AAC3D,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAA;AAEhD,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAG3D,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,aAAa,uBAAiC,CAAA;AAC3D,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAA;AAEhD,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,KAAK,IAAI,MAElD,CAAA;AAED,eAAO,MAAM,QAAQ;;;CAAyC,CAAA;AAG9D,MAAM,WAAW,YAAa,SAAQ,WAAW;IAE/C,MAAM,EAAE,MAAM,CAAA;CACf;AAGD,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,WAAW,GAAG,YAAY,GAAG,CAAC,GAAG,YAAY,CAAA"}
|
package/dist/node/Schema.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export declare const PayloadSchema: "network.xyo.payload";
|
|
|
4
4
|
export type PayloadSchema = typeof PayloadSchema;
|
|
5
5
|
export declare const isSchema: (value: unknown) => value is Schema;
|
|
6
6
|
export declare const asSchema: {
|
|
7
|
-
<TType extends string>(value: import("
|
|
8
|
-
<TType extends string>(value: import("
|
|
7
|
+
<TType extends string>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
8
|
+
<TType extends string>(value: import(".store/@xylabs-promise-npm-3.6.5-91213d5428/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<string>, config?: import("@xylabs/object").TypeCheckConfig): TType;
|
|
9
9
|
};
|
|
10
10
|
export interface SchemaFields extends EmptyObject {
|
|
11
11
|
schema: Schema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAG3D,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,aAAa,uBAAiC,CAAA;AAC3D,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAA;AAEhD,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAG3D,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,aAAa,uBAAiC,CAAA;AAC3D,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAA;AAEhD,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,KAAK,IAAI,MAElD,CAAA;AAED,eAAO,MAAM,QAAQ;;;CAAyC,CAAA;AAG9D,MAAM,WAAW,YAAa,SAAQ,WAAW;IAE/C,MAAM,EAAE,MAAM,CAAA;CACf;AAGD,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,WAAW,GAAG,YAAY,GAAG,CAAC,GAAG,YAAY,CAAA"}
|
package/dist/node/index.cjs
CHANGED
|
@@ -3,7 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
6
|
var __export = (target, all) => {
|
|
8
7
|
for (var name in all)
|
|
9
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -43,54 +42,54 @@ module.exports = __toCommonJS(src_exports);
|
|
|
43
42
|
|
|
44
43
|
// src/isPayload.ts
|
|
45
44
|
var import_object = require("@xylabs/object");
|
|
46
|
-
var isAnyPayload =
|
|
45
|
+
var isAnyPayload = (value) => {
|
|
47
46
|
if ((0, import_object.isObject)(value)) {
|
|
48
47
|
return typeof value.schema === "string";
|
|
49
48
|
}
|
|
50
49
|
return false;
|
|
51
|
-
}
|
|
50
|
+
};
|
|
52
51
|
var asAnyPayload = import_object.AsObjectFactory.create(isAnyPayload);
|
|
53
|
-
var isPayload =
|
|
52
|
+
var isPayload = (schema) => (value) => {
|
|
54
53
|
if (isAnyPayload(value)) {
|
|
55
54
|
return schema.includes(value.schema);
|
|
56
55
|
}
|
|
57
56
|
return false;
|
|
58
|
-
}
|
|
59
|
-
var asPayload =
|
|
57
|
+
};
|
|
58
|
+
var asPayload = (schema) => import_object.AsObjectFactory.create((value) => isPayload(schema)(value));
|
|
60
59
|
|
|
61
60
|
// src/isPayloadOfSchemaType.ts
|
|
62
|
-
var isPayloadOfSchemaType =
|
|
61
|
+
var isPayloadOfSchemaType = (schema) => {
|
|
63
62
|
return (x) => isAnyPayload(x) && (x == null ? void 0 : x.schema) === schema;
|
|
64
|
-
}
|
|
65
|
-
var isPayloadOfSchemaTypeWithMeta =
|
|
63
|
+
};
|
|
64
|
+
var isPayloadOfSchemaTypeWithMeta = (schema) => {
|
|
66
65
|
return (x) => isPayloadOfSchemaType(schema)(x) && x.$hash !== void 0;
|
|
67
|
-
}
|
|
68
|
-
var isPayloadOfSchemaTypeWithSources =
|
|
66
|
+
};
|
|
67
|
+
var isPayloadOfSchemaTypeWithSources = (schema) => {
|
|
69
68
|
return (x) => isPayloadOfSchemaType(schema)(x) && x.sources !== void 0 && Array.isArray(x.sources);
|
|
70
|
-
}
|
|
71
|
-
var notPayloadOfSchemaType =
|
|
69
|
+
};
|
|
70
|
+
var notPayloadOfSchemaType = (schema) => {
|
|
72
71
|
return (x) => !isAnyPayload(x) || (x == null ? void 0 : x.schema) !== schema;
|
|
73
|
-
}
|
|
72
|
+
};
|
|
74
73
|
|
|
75
74
|
// src/Error.ts
|
|
76
75
|
var ModuleErrorSchema = "network.xyo.error.module";
|
|
77
76
|
var isModuleError = isPayloadOfSchemaType(ModuleErrorSchema);
|
|
78
77
|
|
|
79
78
|
// src/isPayloadWithHash.ts
|
|
80
|
-
var isWithHash =
|
|
79
|
+
var isWithHash = (value) => {
|
|
81
80
|
return typeof (value == null ? void 0 : value.$hash) === "string";
|
|
82
|
-
}
|
|
83
|
-
var isPayloadWithHash =
|
|
81
|
+
};
|
|
82
|
+
var isPayloadWithHash = (value) => {
|
|
84
83
|
return isAnyPayload(value) && isWithHash(value);
|
|
85
|
-
}
|
|
84
|
+
};
|
|
86
85
|
|
|
87
86
|
// src/Meta.ts
|
|
88
|
-
var unMeta =
|
|
87
|
+
var unMeta = (payload) => {
|
|
89
88
|
if (payload) {
|
|
90
89
|
const { $meta, $hash, ...result } = payload;
|
|
91
90
|
return result;
|
|
92
91
|
}
|
|
93
|
-
}
|
|
92
|
+
};
|
|
94
93
|
|
|
95
94
|
// src/PayloadSet/PayloadSetSchema.ts
|
|
96
95
|
var PayloadSetSchema = "network.xyo.payload.set";
|
|
@@ -98,12 +97,9 @@ var PayloadSetSchema = "network.xyo.payload.set";
|
|
|
98
97
|
// src/Schema.ts
|
|
99
98
|
var import_object2 = require("@xylabs/object");
|
|
100
99
|
var PayloadSchema = "network.xyo.payload";
|
|
101
|
-
var isSchema =
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
return false;
|
|
106
|
-
}, "isSchema");
|
|
100
|
+
var isSchema = (value) => {
|
|
101
|
+
return typeof value === "string";
|
|
102
|
+
};
|
|
107
103
|
var asSchema = import_object2.AsTypeFactory.create(isSchema);
|
|
108
104
|
// Annotate the CommonJS export names for ESM import in node:
|
|
109
105
|
0 && (module.exports = {
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/Meta.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["export * from './Error.js'\nexport * from './isPayload.js'\nexport * from './isPayloadOfSchemaType.js'\nexport * from './isPayloadWithHash.js'\nexport * from './Meta.js'\nexport * from './Payload.js'\nexport * from './PayloadFindFilter.js'\nexport * from './PayloadSet/index.js'\nexport * from './PayloadValidationFunction.js'\nexport * from './PayloadValueExpression.js'\nexport * from './Query.js'\nexport * from './Schema.js'\n","import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload.js'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload =\n <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.js'\nimport { WithMeta } from './Meta.js'\nimport { Payload, WithSources } from './Payload.js'\n\nexport const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithMeta = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithMeta<T> => isPayloadOfSchemaType<WithMeta<T>>(schema)(x) && x.$hash !== undefined\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n//test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\nconst testWithMeta: WithMeta<Test> = { $hash: '1234abcd', $meta: { timestamp: Date.now() }, field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\nconst testMetaPayloads: WithMeta<Payload>[] = [testWithMeta]\n\nconst testType: Test = testWithMeta\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMeta: Payload[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMetaWithMeta: PayloadWithMeta[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n\nconst isTestFromMetaTypedWithMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestWithMeta: WithMeta<Test>[] = testPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\nconst isTestWithMetaFromMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\n*/\n","import { Hash } from '@xylabs/hex'\nimport { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.js'\nimport { Payload } from './Payload.js'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload.js'\nimport { WithMeta } from './Meta.js'\nimport { Payload } from './Payload.js'\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isWithHash = <T extends Payload>(value: T): value is WithMeta<T> => {\n return typeof (value as WithMeta<T>)?.$hash === 'string'\n}\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isPayloadWithHash = <T extends Payload>(value: unknown): value is WithMeta<T> => {\n return isAnyPayload(value) && isWithHash(value)\n}\n","import { EmptyObject, JsonObject } from '@xylabs/object'\n\nimport { Payload, PayloadMetaFields } from './Payload.js'\nimport { Schema, WithSchema } from './Schema.js'\n\nexport type WithMeta<T extends Payload = Payload, M extends JsonObject | void = void> = PayloadMetaFields<M> & T\nexport type WithOptionalMeta<T extends Payload = Payload, M extends JsonObject | void = void> = Partial<WithMeta<T, M>> &\n Omit<WithMeta<T, M>, '$hash'>\n\nexport type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>\n\nexport const unMeta = <T extends WithMeta<Payload>>(payload?: T): T | undefined => {\n if (payload) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { $meta, $hash, ...result } = payload\n return result as T\n }\n}\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import { AsTypeFactory, EmptyObject } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/Meta.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["export * from './Error.js'\nexport * from './isPayload.js'\nexport * from './isPayloadOfSchemaType.js'\nexport * from './isPayloadWithHash.js'\nexport * from './Meta.js'\nexport * from './Payload.js'\nexport * from './PayloadFindFilter.js'\nexport * from './PayloadSet/index.js'\nexport * from './PayloadValidationFunction.js'\nexport * from './PayloadValueExpression.js'\nexport * from './Query.js'\nexport * from './Schema.js'\n","import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload.js'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload =\n <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.js'\nimport { WithMeta } from './Meta.js'\nimport { Payload, WithSources } from './Payload.js'\n\nexport const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithMeta = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithMeta<T> => isPayloadOfSchemaType<WithMeta<T>>(schema)(x) && x.$hash !== undefined\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n//test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\nconst testWithMeta: WithMeta<Test> = { $hash: '1234abcd', $meta: { timestamp: Date.now() }, field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\nconst testMetaPayloads: WithMeta<Payload>[] = [testWithMeta]\n\nconst testType: Test = testWithMeta\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMeta: Payload[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMetaWithMeta: PayloadWithMeta[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n\nconst isTestFromMetaTypedWithMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestWithMeta: WithMeta<Test>[] = testPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\nconst isTestWithMetaFromMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\n*/\n","import { Hash } from '@xylabs/hex'\nimport { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.js'\nimport { Payload } from './Payload.js'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isAnyPayload } from './isPayload.js'\nimport { WithMeta } from './Meta.js'\nimport { Payload } from './Payload.js'\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isWithHash = <T extends Payload>(value: T): value is WithMeta<T> => {\n return typeof (value as WithMeta<T>)?.$hash === 'string'\n}\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isPayloadWithHash = <T extends Payload>(value: unknown): value is WithMeta<T> => {\n return isAnyPayload(value) && isWithHash(value)\n}\n","import { EmptyObject, JsonObject } from '@xylabs/object'\n\nimport { Payload, PayloadMetaFields } from './Payload.js'\nimport { Schema, WithSchema } from './Schema.js'\n\nexport type WithMeta<T extends Payload = Payload, M extends JsonObject | void = void> = PayloadMetaFields<M> & T\nexport type WithOptionalMeta<T extends Payload = Payload, M extends JsonObject | void = void> = Partial<WithMeta<T, M>> &\n Omit<WithMeta<T, M>, '$hash'>\n\nexport type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>\n\nexport const unMeta = <T extends WithMeta<Payload>>(payload?: T): T | undefined => {\n if (payload) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { $meta, $hash, ...result } = payload\n return result as T\n }\n}\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import { AsTypeFactory, EmptyObject } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAA0C;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,UAAI,wBAAS,KAAK,GAAG;AACnB,WAAO,OAAO,MAAM,WAAW;AAAA,EACjC;AACA,SAAO;AACT;AAEO,IAAM,eAAe,8BAAgB,OAAO,YAAY;AAExD,IAAM,YACX,CAAoB,WACpB,CAAC,UAA+B;AAC9B,MAAI,aAAa,KAAK,GAAG;AACvB,WAAO,OAAO,SAAS,MAAM,MAAM;AAAA,EACrC;AACA,SAAO;AACT;AAEK,IAAM,YAAY,CAAoB,WAAqB,8BAAgB,OAAO,CAAC,UAA+B,UAAU,MAAM,EAAE,KAAK,CAAC;;;AClB1I,IAAM,wBAAwB,CAAoB,WAAmB;AAC1E,SAAO,CAAC,MAA+B,aAAa,CAAC,MAAK,uBAAG,YAAW;AAC1E;AAEO,IAAM,gCAAgC,CAAoB,WAAmB;AAClF,SAAO,CAAC,MAAyC,sBAAmC,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU;AAChH;AAEO,IAAM,mCAAmC,CAAoB,WAAmB;AACrF,SAAO,CAAC,MACN,sBAAsC,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,UAAa,MAAM,QAAQ,EAAE,OAAO;AAC1G;AAEO,IAAM,yBAAyB,CAAoB,WAAmB;AAC3E,SAAO,CAAC,MAA+B,CAAC,aAAa,CAAC,MAAK,uBAAG,YAAW;AAC3E;;;ACZO,IAAM,oBAAuC;AAW7C,IAAM,gBAAgB,sBAAmC,iBAAiB;;;ACT1E,IAAM,aAAa,CAAoB,UAAmC;AAC/E,SAAO,QAAQ,+BAAuB,WAAU;AAClD;AAOO,IAAM,oBAAoB,CAAoB,UAAyC;AAC5F,SAAO,aAAa,KAAK,KAAK,WAAW,KAAK;AAChD;;;ACTO,IAAM,SAAS,CAA8B,YAA+B;AACjF,MAAI,SAAS;AAEX,UAAM,EAAE,OAAO,OAAO,GAAG,OAAO,IAAI;AACpC,WAAO;AAAA,EACT;AACF;;;AChBO,IAAM,mBAAqC;;;ACDlD,IAAAA,iBAA2C;AAKpC,IAAM,gBAAgB;AAGtB,IAAM,WAAW,CAAC,UAAoC;AAC3D,SAAO,OAAO,UAAU;AAC1B;AAEO,IAAM,WAAW,6BAAc,OAAe,QAAQ;","names":["import_object"]}
|
package/dist/node/index.js
CHANGED
|
@@ -1,56 +1,53 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/isPayload.ts
|
|
5
2
|
import { AsObjectFactory, isObject } from "@xylabs/object";
|
|
6
|
-
var isAnyPayload =
|
|
3
|
+
var isAnyPayload = (value) => {
|
|
7
4
|
if (isObject(value)) {
|
|
8
5
|
return typeof value.schema === "string";
|
|
9
6
|
}
|
|
10
7
|
return false;
|
|
11
|
-
}
|
|
8
|
+
};
|
|
12
9
|
var asAnyPayload = AsObjectFactory.create(isAnyPayload);
|
|
13
|
-
var isPayload =
|
|
10
|
+
var isPayload = (schema) => (value) => {
|
|
14
11
|
if (isAnyPayload(value)) {
|
|
15
12
|
return schema.includes(value.schema);
|
|
16
13
|
}
|
|
17
14
|
return false;
|
|
18
|
-
}
|
|
19
|
-
var asPayload =
|
|
15
|
+
};
|
|
16
|
+
var asPayload = (schema) => AsObjectFactory.create((value) => isPayload(schema)(value));
|
|
20
17
|
|
|
21
18
|
// src/isPayloadOfSchemaType.ts
|
|
22
|
-
var isPayloadOfSchemaType =
|
|
19
|
+
var isPayloadOfSchemaType = (schema) => {
|
|
23
20
|
return (x) => isAnyPayload(x) && (x == null ? void 0 : x.schema) === schema;
|
|
24
|
-
}
|
|
25
|
-
var isPayloadOfSchemaTypeWithMeta =
|
|
21
|
+
};
|
|
22
|
+
var isPayloadOfSchemaTypeWithMeta = (schema) => {
|
|
26
23
|
return (x) => isPayloadOfSchemaType(schema)(x) && x.$hash !== void 0;
|
|
27
|
-
}
|
|
28
|
-
var isPayloadOfSchemaTypeWithSources =
|
|
24
|
+
};
|
|
25
|
+
var isPayloadOfSchemaTypeWithSources = (schema) => {
|
|
29
26
|
return (x) => isPayloadOfSchemaType(schema)(x) && x.sources !== void 0 && Array.isArray(x.sources);
|
|
30
|
-
}
|
|
31
|
-
var notPayloadOfSchemaType =
|
|
27
|
+
};
|
|
28
|
+
var notPayloadOfSchemaType = (schema) => {
|
|
32
29
|
return (x) => !isAnyPayload(x) || (x == null ? void 0 : x.schema) !== schema;
|
|
33
|
-
}
|
|
30
|
+
};
|
|
34
31
|
|
|
35
32
|
// src/Error.ts
|
|
36
33
|
var ModuleErrorSchema = "network.xyo.error.module";
|
|
37
34
|
var isModuleError = isPayloadOfSchemaType(ModuleErrorSchema);
|
|
38
35
|
|
|
39
36
|
// src/isPayloadWithHash.ts
|
|
40
|
-
var isWithHash =
|
|
37
|
+
var isWithHash = (value) => {
|
|
41
38
|
return typeof (value == null ? void 0 : value.$hash) === "string";
|
|
42
|
-
}
|
|
43
|
-
var isPayloadWithHash =
|
|
39
|
+
};
|
|
40
|
+
var isPayloadWithHash = (value) => {
|
|
44
41
|
return isAnyPayload(value) && isWithHash(value);
|
|
45
|
-
}
|
|
42
|
+
};
|
|
46
43
|
|
|
47
44
|
// src/Meta.ts
|
|
48
|
-
var unMeta =
|
|
45
|
+
var unMeta = (payload) => {
|
|
49
46
|
if (payload) {
|
|
50
47
|
const { $meta, $hash, ...result } = payload;
|
|
51
48
|
return result;
|
|
52
49
|
}
|
|
53
|
-
}
|
|
50
|
+
};
|
|
54
51
|
|
|
55
52
|
// src/PayloadSet/PayloadSetSchema.ts
|
|
56
53
|
var PayloadSetSchema = "network.xyo.payload.set";
|
|
@@ -58,12 +55,9 @@ var PayloadSetSchema = "network.xyo.payload.set";
|
|
|
58
55
|
// src/Schema.ts
|
|
59
56
|
import { AsTypeFactory } from "@xylabs/object";
|
|
60
57
|
var PayloadSchema = "network.xyo.payload";
|
|
61
|
-
var isSchema =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
return false;
|
|
66
|
-
}, "isSchema");
|
|
58
|
+
var isSchema = (value) => {
|
|
59
|
+
return typeof value === "string";
|
|
60
|
+
};
|
|
67
61
|
var asSchema = AsTypeFactory.create(isSchema);
|
|
68
62
|
export {
|
|
69
63
|
ModuleErrorSchema,
|