@xyo-network/payload-model 2.102.6 → 2.103.0
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 +1 -1
- package/dist/browser/Schema.d.cts.map +1 -1
- package/dist/browser/Schema.d.mts +1 -1
- package/dist/browser/Schema.d.mts.map +1 -1
- package/dist/browser/Schema.d.ts +1 -1
- package/dist/browser/Schema.d.ts.map +1 -1
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/Schema.d.cts +1 -1
- package/dist/neutral/Schema.d.cts.map +1 -1
- package/dist/neutral/Schema.d.mts +1 -1
- package/dist/neutral/Schema.d.mts.map +1 -1
- package/dist/neutral/Schema.d.ts +1 -1
- package/dist/neutral/Schema.d.ts.map +1 -1
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/Schema.d.cts +1 -1
- package/dist/node/Schema.d.cts.map +1 -1
- package/dist/node/Schema.d.mts +1 -1
- package/dist/node/Schema.d.mts.map +1 -1
- package/dist/node/Schema.d.ts +1 -1
- package/dist/node/Schema.d.ts.map +1 -1
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Schema.ts +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EmptyObject } from '@xylabs/object';
|
|
2
2
|
/** Schema type in Javascript is a string */
|
|
3
3
|
export type Schema = string;
|
|
4
|
-
export declare const PayloadSchema
|
|
4
|
+
export declare const PayloadSchema: "network.xyo.payload";
|
|
5
5
|
export type PayloadSchema = typeof PayloadSchema;
|
|
6
6
|
export declare const isSchema: (value: unknown) => value is string;
|
|
7
7
|
export declare const asSchema: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,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,oBAKtC,CAAA;AAED,eAAO,MAAM,QAAQ;;;CAAyC,CAAA;AAE9D,kCAAkC;AAClC,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAA;CACf;AAED,yCAAyC;AACzC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,WAAW,GAAG,YAAY,GAAG,CAAC,GAAG,YAAY,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EmptyObject } from '@xylabs/object';
|
|
2
2
|
/** Schema type in Javascript is a string */
|
|
3
3
|
export type Schema = string;
|
|
4
|
-
export declare const PayloadSchema
|
|
4
|
+
export declare const PayloadSchema: "network.xyo.payload";
|
|
5
5
|
export type PayloadSchema = typeof PayloadSchema;
|
|
6
6
|
export declare const isSchema: (value: unknown) => value is string;
|
|
7
7
|
export declare const asSchema: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,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,oBAKtC,CAAA;AAED,eAAO,MAAM,QAAQ;;;CAAyC,CAAA;AAE9D,kCAAkC;AAClC,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAA;CACf;AAED,yCAAyC;AACzC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,WAAW,GAAG,YAAY,GAAG,CAAC,GAAG,YAAY,CAAA"}
|
package/dist/browser/Schema.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EmptyObject } from '@xylabs/object';
|
|
2
2
|
/** Schema type in Javascript is a string */
|
|
3
3
|
export type Schema = string;
|
|
4
|
-
export declare const PayloadSchema
|
|
4
|
+
export declare const PayloadSchema: "network.xyo.payload";
|
|
5
5
|
export type PayloadSchema = typeof PayloadSchema;
|
|
6
6
|
export declare const isSchema: (value: unknown) => value is string;
|
|
7
7
|
export declare const asSchema: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,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,oBAKtC,CAAA;AAED,eAAO,MAAM,QAAQ;;;CAAyC,CAAA;AAE9D,kCAAkC;AAClC,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAA;CACf;AAED,yCAAyC;AACzC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,WAAW,GAAG,YAAY,GAAG,CAAC,GAAG,YAAY,CAAA"}
|
|
@@ -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'\nexport * from './isPayload'\nexport * from './isPayloadOfSchemaType'\nexport * from './isPayloadWithHash'\nexport * from './Meta'\nexport * from './Payload'\nexport * from './PayloadFindFilter'\nexport * from './PayloadSet'\nexport * from './PayloadValidationFunction'\nexport * from './PayloadValueExpression'\nexport * from './Query'\nexport * from './Schema'\n","import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload, WithSources } from './Payload'\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'\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload } from './Payload'\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'\nimport { Schema, WithSchema } from './Schema'\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'\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n if (typeof value === 'string') {\n return true\n }\n return false\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;;;;;;;;;;;;;;;;;;;;;;;ACAA,oBAA0C;AAInC,IAAMA,eAAe,wBAACC,UAAAA;AAC3B,UAAIC,wBAASD,KAAAA,GAAQ;AACnB,WAAO,OAAOA,MAAME,WAAW;EACjC;AACA,SAAO;AACT,GAL4B;AAOrB,IAAMC,eAAeC,8BAAgBC,OAAON,YAAAA;AAE5C,IAAMO,YACX,wBAAoBJ,WACpB,CAACF,UAAAA;AACC,MAAID,aAAaC,KAAAA,GAAQ;AACvB,WAAOE,OAAOK,SAASP,MAAME,MAAM;EACrC;AACA,SAAO;AACT,GANA;AAQK,IAAMM,YAAY,wBAAoBN,WAAqBE,8BAAgBC,OAAO,CAACL,UAA+BM,UAAUJ,MAAAA,EAAQF,KAAAA,CAAAA,GAAlH;;;AClBlB,IAAMS,wBAAwB,wBAAoBC,WAAAA;AACvD,SAAO,CAACC,MAA+BC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC1E,GAFqC;AAI9B,IAAMG,gCAAgC,wBAAoBH,WAAAA;AAC/D,SAAO,CAACC,MAAyCF,sBAAmCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEG,UAAUC;AAChH,GAF6C;AAItC,IAAMC,mCAAmC,wBAAoBN,WAAAA;AAClE,SAAO,CAACC,MACNF,sBAAsCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEM,YAAYF,UAAaG,MAAMC,QAAQR,EAAEM,OAAO;AAC1G,GAHgD;AAKzC,IAAMG,yBAAyB,wBAAoBV,WAAAA;AACxD,SAAO,CAACC,MAA+B,CAACC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC3E,GAFsC;;;ACV/B,IAAMW,oBAAuC;AAW7C,IAAMC,gBAAgBC,sBAAmCF,iBAAAA;;;ACTzD,IAAMG,aAAa,wBAAoBC,UAAAA;AAC5C,SAAO,OAAQA,OAAuBC,UAAU;AAClD,GAF0B;AASnB,IAAMC,oBAAoB,wBAAoBF,UAAAA;AACnD,SAAOG,aAAaH,KAAAA,KAAUD,WAAWC,KAAAA;AAC3C,GAFiC;;;ACP1B,IAAMI,SAAS,wBAA8BC,YAAAA;AAClD,MAAIA,SAAS;AAEX,UAAM,EAAEC,OAAOC,OAAO,GAAGC,OAAAA,IAAWH;AACpC,WAAOG;EACT;AACF,GANsB;;;ACVf,IAAMC,mBAAqC;;;ACDlD,IAAAC,iBAA2C;AAKpC,IAAMC,gBAAgB;AAGtB,IAAMC,WAAW,wBAACC,UAAAA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,6BAAcC,OAAeJ,QAAAA;","names":["isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","isPayloadOfSchemaTypeWithSources","sources","Array","isArray","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","import_object","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
|
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'\nexport * from './isPayload'\nexport * from './isPayloadOfSchemaType'\nexport * from './isPayloadWithHash'\nexport * from './Meta'\nexport * from './Payload'\nexport * from './PayloadFindFilter'\nexport * from './PayloadSet'\nexport * from './PayloadValidationFunction'\nexport * from './PayloadValueExpression'\nexport * from './Query'\nexport * from './Schema'\n","import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload, WithSources } from './Payload'\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'\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload } from './Payload'\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'\nimport { Schema, WithSchema } from './Schema'\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 if (typeof value === 'string') {\n return true\n }\n return false\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;;;;;;;;;;;;;;;;;;;;;;;ACAA,oBAA0C;AAInC,IAAMA,eAAe,wBAACC,UAAAA;AAC3B,UAAIC,wBAASD,KAAAA,GAAQ;AACnB,WAAO,OAAOA,MAAME,WAAW;EACjC;AACA,SAAO;AACT,GAL4B;AAOrB,IAAMC,eAAeC,8BAAgBC,OAAON,YAAAA;AAE5C,IAAMO,YACX,wBAAoBJ,WACpB,CAACF,UAAAA;AACC,MAAID,aAAaC,KAAAA,GAAQ;AACvB,WAAOE,OAAOK,SAASP,MAAME,MAAM;EACrC;AACA,SAAO;AACT,GANA;AAQK,IAAMM,YAAY,wBAAoBN,WAAqBE,8BAAgBC,OAAO,CAACL,UAA+BM,UAAUJ,MAAAA,EAAQF,KAAAA,CAAAA,GAAlH;;;AClBlB,IAAMS,wBAAwB,wBAAoBC,WAAAA;AACvD,SAAO,CAACC,MAA+BC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC1E,GAFqC;AAI9B,IAAMG,gCAAgC,wBAAoBH,WAAAA;AAC/D,SAAO,CAACC,MAAyCF,sBAAmCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEG,UAAUC;AAChH,GAF6C;AAItC,IAAMC,mCAAmC,wBAAoBN,WAAAA;AAClE,SAAO,CAACC,MACNF,sBAAsCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEM,YAAYF,UAAaG,MAAMC,QAAQR,EAAEM,OAAO;AAC1G,GAHgD;AAKzC,IAAMG,yBAAyB,wBAAoBV,WAAAA;AACxD,SAAO,CAACC,MAA+B,CAACC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC3E,GAFsC;;;ACV/B,IAAMW,oBAAuC;AAW7C,IAAMC,gBAAgBC,sBAAmCF,iBAAAA;;;ACTzD,IAAMG,aAAa,wBAAoBC,UAAAA;AAC5C,SAAO,OAAQA,OAAuBC,UAAU;AAClD,GAF0B;AASnB,IAAMC,oBAAoB,wBAAoBF,UAAAA;AACnD,SAAOG,aAAaH,KAAAA,KAAUD,WAAWC,KAAAA;AAC3C,GAFiC;;;ACP1B,IAAMI,SAAS,wBAA8BC,YAAAA;AAClD,MAAIA,SAAS;AAEX,UAAM,EAAEC,OAAOC,OAAO,GAAGC,OAAAA,IAAWH;AACpC,WAAOG;EACT;AACF,GANsB;;;ACVf,IAAMC,mBAAqC;;;ACDlD,IAAAC,iBAA2C;AAKpC,IAAMC,gBAAgB;AAGtB,IAAMC,WAAW,wBAACC,UAAAA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,6BAAcC,OAAeJ,QAAAA;","names":["isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","isPayloadOfSchemaTypeWithSources","sources","Array","isArray","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","import_object","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
|
@@ -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'\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'\nimport { WithMeta } from './Meta'\nimport { Payload, WithSources } from './Payload'\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'\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload } from './Payload'\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'\nimport { Schema, WithSchema } from './Schema'\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'\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n if (typeof value === 'string') {\n return true\n }\n return false\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,SAASA,iBAAiBC,gBAAgB;AAInC,IAAMC,eAAe,wBAACC,UAAAA;AAC3B,MAAIC,SAASD,KAAAA,GAAQ;AACnB,WAAO,OAAOA,MAAME,WAAW;EACjC;AACA,SAAO;AACT,GAL4B;AAOrB,IAAMC,eAAeC,gBAAgBC,OAAON,YAAAA;AAE5C,IAAMO,YACX,wBAAoBJ,WACpB,CAACF,UAAAA;AACC,MAAID,aAAaC,KAAAA,GAAQ;AACvB,WAAOE,OAAOK,SAASP,MAAME,MAAM;EACrC;AACA,SAAO;AACT,GANA;AAQK,IAAMM,YAAY,wBAAoBN,WAAqBE,gBAAgBC,OAAO,CAACL,UAA+BM,UAAUJ,MAAAA,EAAQF,KAAAA,CAAAA,GAAlH;;;AClBlB,IAAMS,wBAAwB,wBAAoBC,WAAAA;AACvD,SAAO,CAACC,MAA+BC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC1E,GAFqC;AAI9B,IAAMG,gCAAgC,wBAAoBH,WAAAA;AAC/D,SAAO,CAACC,MAAyCF,sBAAmCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEG,UAAUC;AAChH,GAF6C;AAItC,IAAMC,mCAAmC,wBAAoBN,WAAAA;AAClE,SAAO,CAACC,MACNF,sBAAsCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEM,YAAYF,UAAaG,MAAMC,QAAQR,EAAEM,OAAO;AAC1G,GAHgD;AAKzC,IAAMG,yBAAyB,wBAAoBV,WAAAA;AACxD,SAAO,CAACC,MAA+B,CAACC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC3E,GAFsC;;;ACV/B,IAAMW,oBAAuC;AAW7C,IAAMC,gBAAgBC,sBAAmCF,iBAAAA;;;ACTzD,IAAMG,aAAa,wBAAoBC,UAAAA;AAC5C,SAAO,OAAQA,OAAuBC,UAAU;AAClD,GAF0B;AASnB,IAAMC,oBAAoB,wBAAoBF,UAAAA;AACnD,SAAOG,aAAaH,KAAAA,KAAUD,WAAWC,KAAAA;AAC3C,GAFiC;;;ACP1B,IAAMI,SAAS,wBAA8BC,YAAAA;AAClD,MAAIA,SAAS;AAEX,UAAM,EAAEC,OAAOC,OAAO,GAAGC,OAAAA,IAAWH;AACpC,WAAOG;EACT;AACF,GANsB;;;ACVf,IAAMC,mBAAqC;;;ACDlD,SAASC,qBAAkC;AAKpC,IAAMC,gBAAgB;AAGtB,IAAMC,WAAW,wBAACC,UAAAA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,cAAcC,OAAeJ,QAAAA;","names":["AsObjectFactory","isObject","isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","isPayloadOfSchemaTypeWithSources","sources","Array","isArray","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","AsTypeFactory","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
|
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'\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'\nimport { WithMeta } from './Meta'\nimport { Payload, WithSources } from './Payload'\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'\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload } from './Payload'\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'\nimport { Schema, WithSchema } from './Schema'\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 if (typeof value === 'string') {\n return true\n }\n return false\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,SAASA,iBAAiBC,gBAAgB;AAInC,IAAMC,eAAe,wBAACC,UAAAA;AAC3B,MAAIC,SAASD,KAAAA,GAAQ;AACnB,WAAO,OAAOA,MAAME,WAAW;EACjC;AACA,SAAO;AACT,GAL4B;AAOrB,IAAMC,eAAeC,gBAAgBC,OAAON,YAAAA;AAE5C,IAAMO,YACX,wBAAoBJ,WACpB,CAACF,UAAAA;AACC,MAAID,aAAaC,KAAAA,GAAQ;AACvB,WAAOE,OAAOK,SAASP,MAAME,MAAM;EACrC;AACA,SAAO;AACT,GANA;AAQK,IAAMM,YAAY,wBAAoBN,WAAqBE,gBAAgBC,OAAO,CAACL,UAA+BM,UAAUJ,MAAAA,EAAQF,KAAAA,CAAAA,GAAlH;;;AClBlB,IAAMS,wBAAwB,wBAAoBC,WAAAA;AACvD,SAAO,CAACC,MAA+BC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC1E,GAFqC;AAI9B,IAAMG,gCAAgC,wBAAoBH,WAAAA;AAC/D,SAAO,CAACC,MAAyCF,sBAAmCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEG,UAAUC;AAChH,GAF6C;AAItC,IAAMC,mCAAmC,wBAAoBN,WAAAA;AAClE,SAAO,CAACC,MACNF,sBAAsCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEM,YAAYF,UAAaG,MAAMC,QAAQR,EAAEM,OAAO;AAC1G,GAHgD;AAKzC,IAAMG,yBAAyB,wBAAoBV,WAAAA;AACxD,SAAO,CAACC,MAA+B,CAACC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC3E,GAFsC;;;ACV/B,IAAMW,oBAAuC;AAW7C,IAAMC,gBAAgBC,sBAAmCF,iBAAAA;;;ACTzD,IAAMG,aAAa,wBAAoBC,UAAAA;AAC5C,SAAO,OAAQA,OAAuBC,UAAU;AAClD,GAF0B;AASnB,IAAMC,oBAAoB,wBAAoBF,UAAAA;AACnD,SAAOG,aAAaH,KAAAA,KAAUD,WAAWC,KAAAA;AAC3C,GAFiC;;;ACP1B,IAAMI,SAAS,wBAA8BC,YAAAA;AAClD,MAAIA,SAAS;AAEX,UAAM,EAAEC,OAAOC,OAAO,GAAGC,OAAAA,IAAWH;AACpC,WAAOG;EACT;AACF,GANsB;;;ACVf,IAAMC,mBAAqC;;;ACDlD,SAASC,qBAAkC;AAKpC,IAAMC,gBAAgB;AAGtB,IAAMC,WAAW,wBAACC,UAAAA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,cAAcC,OAAeJ,QAAAA;","names":["AsObjectFactory","isObject","isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","isPayloadOfSchemaTypeWithSources","sources","Array","isArray","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","AsTypeFactory","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EmptyObject } from '@xylabs/object';
|
|
2
2
|
/** Schema type in Javascript is a string */
|
|
3
3
|
export type Schema = string;
|
|
4
|
-
export declare const PayloadSchema
|
|
4
|
+
export declare const PayloadSchema: "network.xyo.payload";
|
|
5
5
|
export type PayloadSchema = typeof PayloadSchema;
|
|
6
6
|
export declare const isSchema: (value: unknown) => value is string;
|
|
7
7
|
export declare const asSchema: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,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,oBAKtC,CAAA;AAED,eAAO,MAAM,QAAQ;;;CAAyC,CAAA;AAE9D,kCAAkC;AAClC,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAA;CACf;AAED,yCAAyC;AACzC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,WAAW,GAAG,YAAY,GAAG,CAAC,GAAG,YAAY,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EmptyObject } from '@xylabs/object';
|
|
2
2
|
/** Schema type in Javascript is a string */
|
|
3
3
|
export type Schema = string;
|
|
4
|
-
export declare const PayloadSchema
|
|
4
|
+
export declare const PayloadSchema: "network.xyo.payload";
|
|
5
5
|
export type PayloadSchema = typeof PayloadSchema;
|
|
6
6
|
export declare const isSchema: (value: unknown) => value is string;
|
|
7
7
|
export declare const asSchema: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,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,oBAKtC,CAAA;AAED,eAAO,MAAM,QAAQ;;;CAAyC,CAAA;AAE9D,kCAAkC;AAClC,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAA;CACf;AAED,yCAAyC;AACzC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,WAAW,GAAG,YAAY,GAAG,CAAC,GAAG,YAAY,CAAA"}
|
package/dist/neutral/Schema.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EmptyObject } from '@xylabs/object';
|
|
2
2
|
/** Schema type in Javascript is a string */
|
|
3
3
|
export type Schema = string;
|
|
4
|
-
export declare const PayloadSchema
|
|
4
|
+
export declare const PayloadSchema: "network.xyo.payload";
|
|
5
5
|
export type PayloadSchema = typeof PayloadSchema;
|
|
6
6
|
export declare const isSchema: (value: unknown) => value is string;
|
|
7
7
|
export declare const asSchema: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,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,oBAKtC,CAAA;AAED,eAAO,MAAM,QAAQ;;;CAAyC,CAAA;AAE9D,kCAAkC;AAClC,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAA;CACf;AAED,yCAAyC;AACzC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,WAAW,GAAG,YAAY,GAAG,CAAC,GAAG,YAAY,CAAA"}
|
|
@@ -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'\nexport * from './isPayload'\nexport * from './isPayloadOfSchemaType'\nexport * from './isPayloadWithHash'\nexport * from './Meta'\nexport * from './Payload'\nexport * from './PayloadFindFilter'\nexport * from './PayloadSet'\nexport * from './PayloadValidationFunction'\nexport * from './PayloadValueExpression'\nexport * from './Query'\nexport * from './Schema'\n","import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload, WithSources } from './Payload'\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'\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload } from './Payload'\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'\nimport { Schema, WithSchema } from './Schema'\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'\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n if (typeof value === 'string') {\n return true\n }\n return false\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;;;;;;;;;;;;;;;;;;;;;;;ACAA,oBAA0C;AAInC,IAAMA,eAAe,wBAACC,UAAAA;AAC3B,UAAIC,wBAASD,KAAAA,GAAQ;AACnB,WAAO,OAAOA,MAAME,WAAW;EACjC;AACA,SAAO;AACT,GAL4B;AAOrB,IAAMC,eAAeC,8BAAgBC,OAAON,YAAAA;AAE5C,IAAMO,YACX,wBAAoBJ,WACpB,CAACF,UAAAA;AACC,MAAID,aAAaC,KAAAA,GAAQ;AACvB,WAAOE,OAAOK,SAASP,MAAME,MAAM;EACrC;AACA,SAAO;AACT,GANA;AAQK,IAAMM,YAAY,wBAAoBN,WAAqBE,8BAAgBC,OAAO,CAACL,UAA+BM,UAAUJ,MAAAA,EAAQF,KAAAA,CAAAA,GAAlH;;;AClBlB,IAAMS,wBAAwB,wBAAoBC,WAAAA;AACvD,SAAO,CAACC,MAA+BC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC1E,GAFqC;AAI9B,IAAMG,gCAAgC,wBAAoBH,WAAAA;AAC/D,SAAO,CAACC,MAAyCF,sBAAmCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEG,UAAUC;AAChH,GAF6C;AAItC,IAAMC,mCAAmC,wBAAoBN,WAAAA;AAClE,SAAO,CAACC,MACNF,sBAAsCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEM,YAAYF,UAAaG,MAAMC,QAAQR,EAAEM,OAAO;AAC1G,GAHgD;AAKzC,IAAMG,yBAAyB,wBAAoBV,WAAAA;AACxD,SAAO,CAACC,MAA+B,CAACC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC3E,GAFsC;;;ACV/B,IAAMW,oBAAuC;AAW7C,IAAMC,gBAAgBC,sBAAmCF,iBAAAA;;;ACTzD,IAAMG,aAAa,wBAAoBC,UAAAA;AAC5C,SAAO,OAAQA,OAAuBC,UAAU;AAClD,GAF0B;AASnB,IAAMC,oBAAoB,wBAAoBF,UAAAA;AACnD,SAAOG,aAAaH,KAAAA,KAAUD,WAAWC,KAAAA;AAC3C,GAFiC;;;ACP1B,IAAMI,SAAS,wBAA8BC,YAAAA;AAClD,MAAIA,SAAS;AAEX,UAAM,EAAEC,OAAOC,OAAO,GAAGC,OAAAA,IAAWH;AACpC,WAAOG;EACT;AACF,GANsB;;;ACVf,IAAMC,mBAAqC;;;ACDlD,IAAAC,iBAA2C;AAKpC,IAAMC,gBAAgB;AAGtB,IAAMC,WAAW,wBAACC,UAAAA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,6BAAcC,OAAeJ,QAAAA;","names":["isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","isPayloadOfSchemaTypeWithSources","sources","Array","isArray","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","import_object","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
|
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'\nexport * from './isPayload'\nexport * from './isPayloadOfSchemaType'\nexport * from './isPayloadWithHash'\nexport * from './Meta'\nexport * from './Payload'\nexport * from './PayloadFindFilter'\nexport * from './PayloadSet'\nexport * from './PayloadValidationFunction'\nexport * from './PayloadValueExpression'\nexport * from './Query'\nexport * from './Schema'\n","import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload, WithSources } from './Payload'\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'\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload } from './Payload'\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'\nimport { Schema, WithSchema } from './Schema'\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 if (typeof value === 'string') {\n return true\n }\n return false\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;;;;;;;;;;;;;;;;;;;;;;;ACAA,oBAA0C;AAInC,IAAMA,eAAe,wBAACC,UAAAA;AAC3B,UAAIC,wBAASD,KAAAA,GAAQ;AACnB,WAAO,OAAOA,MAAME,WAAW;EACjC;AACA,SAAO;AACT,GAL4B;AAOrB,IAAMC,eAAeC,8BAAgBC,OAAON,YAAAA;AAE5C,IAAMO,YACX,wBAAoBJ,WACpB,CAACF,UAAAA;AACC,MAAID,aAAaC,KAAAA,GAAQ;AACvB,WAAOE,OAAOK,SAASP,MAAME,MAAM;EACrC;AACA,SAAO;AACT,GANA;AAQK,IAAMM,YAAY,wBAAoBN,WAAqBE,8BAAgBC,OAAO,CAACL,UAA+BM,UAAUJ,MAAAA,EAAQF,KAAAA,CAAAA,GAAlH;;;AClBlB,IAAMS,wBAAwB,wBAAoBC,WAAAA;AACvD,SAAO,CAACC,MAA+BC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC1E,GAFqC;AAI9B,IAAMG,gCAAgC,wBAAoBH,WAAAA;AAC/D,SAAO,CAACC,MAAyCF,sBAAmCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEG,UAAUC;AAChH,GAF6C;AAItC,IAAMC,mCAAmC,wBAAoBN,WAAAA;AAClE,SAAO,CAACC,MACNF,sBAAsCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEM,YAAYF,UAAaG,MAAMC,QAAQR,EAAEM,OAAO;AAC1G,GAHgD;AAKzC,IAAMG,yBAAyB,wBAAoBV,WAAAA;AACxD,SAAO,CAACC,MAA+B,CAACC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC3E,GAFsC;;;ACV/B,IAAMW,oBAAuC;AAW7C,IAAMC,gBAAgBC,sBAAmCF,iBAAAA;;;ACTzD,IAAMG,aAAa,wBAAoBC,UAAAA;AAC5C,SAAO,OAAQA,OAAuBC,UAAU;AAClD,GAF0B;AASnB,IAAMC,oBAAoB,wBAAoBF,UAAAA;AACnD,SAAOG,aAAaH,KAAAA,KAAUD,WAAWC,KAAAA;AAC3C,GAFiC;;;ACP1B,IAAMI,SAAS,wBAA8BC,YAAAA;AAClD,MAAIA,SAAS;AAEX,UAAM,EAAEC,OAAOC,OAAO,GAAGC,OAAAA,IAAWH;AACpC,WAAOG;EACT;AACF,GANsB;;;ACVf,IAAMC,mBAAqC;;;ACDlD,IAAAC,iBAA2C;AAKpC,IAAMC,gBAAgB;AAGtB,IAAMC,WAAW,wBAACC,UAAAA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,6BAAcC,OAAeJ,QAAAA;","names":["isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","isPayloadOfSchemaTypeWithSources","sources","Array","isArray","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","import_object","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
|
@@ -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'\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'\nimport { WithMeta } from './Meta'\nimport { Payload, WithSources } from './Payload'\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'\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload } from './Payload'\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'\nimport { Schema, WithSchema } from './Schema'\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'\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n if (typeof value === 'string') {\n return true\n }\n return false\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,SAASA,iBAAiBC,gBAAgB;AAInC,IAAMC,eAAe,wBAACC,UAAAA;AAC3B,MAAIC,SAASD,KAAAA,GAAQ;AACnB,WAAO,OAAOA,MAAME,WAAW;EACjC;AACA,SAAO;AACT,GAL4B;AAOrB,IAAMC,eAAeC,gBAAgBC,OAAON,YAAAA;AAE5C,IAAMO,YACX,wBAAoBJ,WACpB,CAACF,UAAAA;AACC,MAAID,aAAaC,KAAAA,GAAQ;AACvB,WAAOE,OAAOK,SAASP,MAAME,MAAM;EACrC;AACA,SAAO;AACT,GANA;AAQK,IAAMM,YAAY,wBAAoBN,WAAqBE,gBAAgBC,OAAO,CAACL,UAA+BM,UAAUJ,MAAAA,EAAQF,KAAAA,CAAAA,GAAlH;;;AClBlB,IAAMS,wBAAwB,wBAAoBC,WAAAA;AACvD,SAAO,CAACC,MAA+BC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC1E,GAFqC;AAI9B,IAAMG,gCAAgC,wBAAoBH,WAAAA;AAC/D,SAAO,CAACC,MAAyCF,sBAAmCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEG,UAAUC;AAChH,GAF6C;AAItC,IAAMC,mCAAmC,wBAAoBN,WAAAA;AAClE,SAAO,CAACC,MACNF,sBAAsCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEM,YAAYF,UAAaG,MAAMC,QAAQR,EAAEM,OAAO;AAC1G,GAHgD;AAKzC,IAAMG,yBAAyB,wBAAoBV,WAAAA;AACxD,SAAO,CAACC,MAA+B,CAACC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC3E,GAFsC;;;ACV/B,IAAMW,oBAAuC;AAW7C,IAAMC,gBAAgBC,sBAAmCF,iBAAAA;;;ACTzD,IAAMG,aAAa,wBAAoBC,UAAAA;AAC5C,SAAO,OAAQA,OAAuBC,UAAU;AAClD,GAF0B;AASnB,IAAMC,oBAAoB,wBAAoBF,UAAAA;AACnD,SAAOG,aAAaH,KAAAA,KAAUD,WAAWC,KAAAA;AAC3C,GAFiC;;;ACP1B,IAAMI,SAAS,wBAA8BC,YAAAA;AAClD,MAAIA,SAAS;AAEX,UAAM,EAAEC,OAAOC,OAAO,GAAGC,OAAAA,IAAWH;AACpC,WAAOG;EACT;AACF,GANsB;;;ACVf,IAAMC,mBAAqC;;;ACDlD,SAASC,qBAAkC;AAKpC,IAAMC,gBAAgB;AAGtB,IAAMC,WAAW,wBAACC,UAAAA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,cAAcC,OAAeJ,QAAAA;","names":["AsObjectFactory","isObject","isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","isPayloadOfSchemaTypeWithSources","sources","Array","isArray","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","AsTypeFactory","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
|
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'\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'\nimport { WithMeta } from './Meta'\nimport { Payload, WithSources } from './Payload'\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'\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload } from './Payload'\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'\nimport { Schema, WithSchema } from './Schema'\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 if (typeof value === 'string') {\n return true\n }\n return false\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,SAASA,iBAAiBC,gBAAgB;AAInC,IAAMC,eAAe,wBAACC,UAAAA;AAC3B,MAAIC,SAASD,KAAAA,GAAQ;AACnB,WAAO,OAAOA,MAAME,WAAW;EACjC;AACA,SAAO;AACT,GAL4B;AAOrB,IAAMC,eAAeC,gBAAgBC,OAAON,YAAAA;AAE5C,IAAMO,YACX,wBAAoBJ,WACpB,CAACF,UAAAA;AACC,MAAID,aAAaC,KAAAA,GAAQ;AACvB,WAAOE,OAAOK,SAASP,MAAME,MAAM;EACrC;AACA,SAAO;AACT,GANA;AAQK,IAAMM,YAAY,wBAAoBN,WAAqBE,gBAAgBC,OAAO,CAACL,UAA+BM,UAAUJ,MAAAA,EAAQF,KAAAA,CAAAA,GAAlH;;;AClBlB,IAAMS,wBAAwB,wBAAoBC,WAAAA;AACvD,SAAO,CAACC,MAA+BC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC1E,GAFqC;AAI9B,IAAMG,gCAAgC,wBAAoBH,WAAAA;AAC/D,SAAO,CAACC,MAAyCF,sBAAmCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEG,UAAUC;AAChH,GAF6C;AAItC,IAAMC,mCAAmC,wBAAoBN,WAAAA;AAClE,SAAO,CAACC,MACNF,sBAAsCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEM,YAAYF,UAAaG,MAAMC,QAAQR,EAAEM,OAAO;AAC1G,GAHgD;AAKzC,IAAMG,yBAAyB,wBAAoBV,WAAAA;AACxD,SAAO,CAACC,MAA+B,CAACC,aAAaD,CAAAA,KAAMA,GAAGD,WAAWA;AAC3E,GAFsC;;;ACV/B,IAAMW,oBAAuC;AAW7C,IAAMC,gBAAgBC,sBAAmCF,iBAAAA;;;ACTzD,IAAMG,aAAa,wBAAoBC,UAAAA;AAC5C,SAAO,OAAQA,OAAuBC,UAAU;AAClD,GAF0B;AASnB,IAAMC,oBAAoB,wBAAoBF,UAAAA;AACnD,SAAOG,aAAaH,KAAAA,KAAUD,WAAWC,KAAAA;AAC3C,GAFiC;;;ACP1B,IAAMI,SAAS,wBAA8BC,YAAAA;AAClD,MAAIA,SAAS;AAEX,UAAM,EAAEC,OAAOC,OAAO,GAAGC,OAAAA,IAAWH;AACpC,WAAOG;EACT;AACF,GANsB;;;ACVf,IAAMC,mBAAqC;;;ACDlD,SAASC,qBAAkC;AAKpC,IAAMC,gBAAgB;AAGtB,IAAMC,WAAW,wBAACC,UAAAA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,cAAcC,OAAeJ,QAAAA;","names":["AsObjectFactory","isObject","isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","isPayloadOfSchemaTypeWithSources","sources","Array","isArray","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","AsTypeFactory","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
package/dist/node/Schema.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EmptyObject } from '@xylabs/object';
|
|
2
2
|
/** Schema type in Javascript is a string */
|
|
3
3
|
export type Schema = string;
|
|
4
|
-
export declare const PayloadSchema
|
|
4
|
+
export declare const PayloadSchema: "network.xyo.payload";
|
|
5
5
|
export type PayloadSchema = typeof PayloadSchema;
|
|
6
6
|
export declare const isSchema: (value: unknown) => value is string;
|
|
7
7
|
export declare const asSchema: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,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,oBAKtC,CAAA;AAED,eAAO,MAAM,QAAQ;;;CAAyC,CAAA;AAE9D,kCAAkC;AAClC,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAA;CACf;AAED,yCAAyC;AACzC,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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EmptyObject } from '@xylabs/object';
|
|
2
2
|
/** Schema type in Javascript is a string */
|
|
3
3
|
export type Schema = string;
|
|
4
|
-
export declare const PayloadSchema
|
|
4
|
+
export declare const PayloadSchema: "network.xyo.payload";
|
|
5
5
|
export type PayloadSchema = typeof PayloadSchema;
|
|
6
6
|
export declare const isSchema: (value: unknown) => value is string;
|
|
7
7
|
export declare const asSchema: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,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,oBAKtC,CAAA;AAED,eAAO,MAAM,QAAQ;;;CAAyC,CAAA;AAE9D,kCAAkC;AAClC,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAA;CACf;AAED,yCAAyC;AACzC,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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EmptyObject } from '@xylabs/object';
|
|
2
2
|
/** Schema type in Javascript is a string */
|
|
3
3
|
export type Schema = string;
|
|
4
|
-
export declare const PayloadSchema
|
|
4
|
+
export declare const PayloadSchema: "network.xyo.payload";
|
|
5
5
|
export type PayloadSchema = typeof PayloadSchema;
|
|
6
6
|
export declare const isSchema: (value: unknown) => value is string;
|
|
7
7
|
export declare const asSchema: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE3D,4CAA4C;AAC5C,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,oBAKtC,CAAA;AAED,eAAO,MAAM,QAAQ;;;CAAyC,CAAA;AAE9D,kCAAkC;AAClC,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAA;CACf;AAED,yCAAyC;AACzC,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.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'\nexport * from './isPayload'\nexport * from './isPayloadOfSchemaType'\nexport * from './isPayloadWithHash'\nexport * from './Meta'\nexport * from './Payload'\nexport * from './PayloadFindFilter'\nexport * from './PayloadSet'\nexport * from './PayloadValidationFunction'\nexport * from './PayloadValueExpression'\nexport * from './Query'\nexport * from './Schema'\n","import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload, WithSources } from './Payload'\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'\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload } from './Payload'\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'\nimport { Schema, WithSchema } from './Schema'\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'\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n if (typeof value === 'string') {\n return true\n }\n return false\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;;;;;;;;;;;;;;;;;;;;;;;ACAA,oBAA0C;AAInC,IAAMA,eAAe,wBAACC,UAAAA;AAC3B,UAAIC,wBAASD,KAAAA,GAAQ;AACnB,WAAO,OAAOA,MAAME,WAAW;EACjC;AACA,SAAO;AACT,GAL4B;AAOrB,IAAMC,eAAeC,8BAAgBC,OAAON,YAAAA;AAE5C,IAAMO,YACX,wBAAoBJ,WACpB,CAACF,UAAAA;AACC,MAAID,aAAaC,KAAAA,GAAQ;AACvB,WAAOE,OAAOK,SAASP,MAAME,MAAM;EACrC;AACA,SAAO;AACT,GANA;AAQK,IAAMM,YAAY,wBAAoBN,WAAqBE,8BAAgBC,OAAO,CAACL,UAA+BM,UAAUJ,MAAAA,EAAQF,KAAAA,CAAAA,GAAlH;;;AClBlB,IAAMS,wBAAwB,wBAAoBC,WAAAA;AACvD,SAAO,CAACC,MAA+BC,aAAaD,CAAAA,MAAMA,uBAAGD,YAAWA;AAC1E,GAFqC;AAI9B,IAAMG,gCAAgC,wBAAoBH,WAAAA;AAC/D,SAAO,CAACC,MAAyCF,sBAAmCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEG,UAAUC;AAChH,GAF6C;AAItC,IAAMC,mCAAmC,wBAAoBN,WAAAA;AAClE,SAAO,CAACC,MACNF,sBAAsCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEM,YAAYF,UAAaG,MAAMC,QAAQR,EAAEM,OAAO;AAC1G,GAHgD;AAKzC,IAAMG,yBAAyB,wBAAoBV,WAAAA;AACxD,SAAO,CAACC,MAA+B,CAACC,aAAaD,CAAAA,MAAMA,uBAAGD,YAAWA;AAC3E,GAFsC;;;ACV/B,IAAMW,oBAAuC;AAW7C,IAAMC,gBAAgBC,sBAAmCF,iBAAAA;;;ACTzD,IAAMG,aAAa,wBAAoBC,UAAAA;AAC5C,SAAO,QAAQA,+BAAuBC,WAAU;AAClD,GAF0B;AASnB,IAAMC,oBAAoB,wBAAoBF,UAAAA;AACnD,SAAOG,aAAaH,KAAAA,KAAUD,WAAWC,KAAAA;AAC3C,GAFiC;;;ACP1B,IAAMI,SAAS,wBAA8BC,YAAAA;AAClD,MAAIA,SAAS;AAEX,UAAM,EAAEC,OAAOC,OAAO,GAAGC,OAAAA,IAAWH;AACpC,WAAOG;EACT;AACF,GANsB;;;ACVf,IAAMC,mBAAqC;;;ACDlD,IAAAC,iBAA2C;AAKpC,IAAMC,gBAAgB;AAGtB,IAAMC,WAAW,wBAACC,UAAAA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,6BAAcC,OAAeJ,QAAAA;","names":["isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","isPayloadOfSchemaTypeWithSources","sources","Array","isArray","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","import_object","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
|
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'\nexport * from './isPayload'\nexport * from './isPayloadOfSchemaType'\nexport * from './isPayloadWithHash'\nexport * from './Meta'\nexport * from './Payload'\nexport * from './PayloadFindFilter'\nexport * from './PayloadSet'\nexport * from './PayloadValidationFunction'\nexport * from './PayloadValueExpression'\nexport * from './Query'\nexport * from './Schema'\n","import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload, WithSources } from './Payload'\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'\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload } from './Payload'\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'\nimport { Schema, WithSchema } from './Schema'\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 if (typeof value === 'string') {\n return true\n }\n return false\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;;;;;;;;;;;;;;;;;;;;;;;ACAA,oBAA0C;AAInC,IAAMA,eAAe,wBAACC,UAAAA;AAC3B,UAAIC,wBAASD,KAAAA,GAAQ;AACnB,WAAO,OAAOA,MAAME,WAAW;EACjC;AACA,SAAO;AACT,GAL4B;AAOrB,IAAMC,eAAeC,8BAAgBC,OAAON,YAAAA;AAE5C,IAAMO,YACX,wBAAoBJ,WACpB,CAACF,UAAAA;AACC,MAAID,aAAaC,KAAAA,GAAQ;AACvB,WAAOE,OAAOK,SAASP,MAAME,MAAM;EACrC;AACA,SAAO;AACT,GANA;AAQK,IAAMM,YAAY,wBAAoBN,WAAqBE,8BAAgBC,OAAO,CAACL,UAA+BM,UAAUJ,MAAAA,EAAQF,KAAAA,CAAAA,GAAlH;;;AClBlB,IAAMS,wBAAwB,wBAAoBC,WAAAA;AACvD,SAAO,CAACC,MAA+BC,aAAaD,CAAAA,MAAMA,uBAAGD,YAAWA;AAC1E,GAFqC;AAI9B,IAAMG,gCAAgC,wBAAoBH,WAAAA;AAC/D,SAAO,CAACC,MAAyCF,sBAAmCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEG,UAAUC;AAChH,GAF6C;AAItC,IAAMC,mCAAmC,wBAAoBN,WAAAA;AAClE,SAAO,CAACC,MACNF,sBAAsCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEM,YAAYF,UAAaG,MAAMC,QAAQR,EAAEM,OAAO;AAC1G,GAHgD;AAKzC,IAAMG,yBAAyB,wBAAoBV,WAAAA;AACxD,SAAO,CAACC,MAA+B,CAACC,aAAaD,CAAAA,MAAMA,uBAAGD,YAAWA;AAC3E,GAFsC;;;ACV/B,IAAMW,oBAAuC;AAW7C,IAAMC,gBAAgBC,sBAAmCF,iBAAAA;;;ACTzD,IAAMG,aAAa,wBAAoBC,UAAAA;AAC5C,SAAO,QAAQA,+BAAuBC,WAAU;AAClD,GAF0B;AASnB,IAAMC,oBAAoB,wBAAoBF,UAAAA;AACnD,SAAOG,aAAaH,KAAAA,KAAUD,WAAWC,KAAAA;AAC3C,GAFiC;;;ACP1B,IAAMI,SAAS,wBAA8BC,YAAAA;AAClD,MAAIA,SAAS;AAEX,UAAM,EAAEC,OAAOC,OAAO,GAAGC,OAAAA,IAAWH;AACpC,WAAOG;EACT;AACF,GANsB;;;ACVf,IAAMC,mBAAqC;;;ACDlD,IAAAC,iBAA2C;AAKpC,IAAMC,gBAAgB;AAGtB,IAAMC,WAAW,wBAACC,UAAAA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,6BAAcC,OAAeJ,QAAAA;","names":["isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","isPayloadOfSchemaTypeWithSources","sources","Array","isArray","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","import_object","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
package/dist/node/index.js.map
CHANGED
|
@@ -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'\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'\nimport { WithMeta } from './Meta'\nimport { Payload, WithSources } from './Payload'\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'\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload } from './Payload'\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'\nimport { Schema, WithSchema } from './Schema'\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'\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n if (typeof value === 'string') {\n return true\n }\n return false\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,SAASA,iBAAiBC,gBAAgB;AAInC,IAAMC,eAAe,wBAACC,UAAAA;AAC3B,MAAIC,SAASD,KAAAA,GAAQ;AACnB,WAAO,OAAOA,MAAME,WAAW;EACjC;AACA,SAAO;AACT,GAL4B;AAOrB,IAAMC,eAAeC,gBAAgBC,OAAON,YAAAA;AAE5C,IAAMO,YACX,wBAAoBJ,WACpB,CAACF,UAAAA;AACC,MAAID,aAAaC,KAAAA,GAAQ;AACvB,WAAOE,OAAOK,SAASP,MAAME,MAAM;EACrC;AACA,SAAO;AACT,GANA;AAQK,IAAMM,YAAY,wBAAoBN,WAAqBE,gBAAgBC,OAAO,CAACL,UAA+BM,UAAUJ,MAAAA,EAAQF,KAAAA,CAAAA,GAAlH;;;AClBlB,IAAMS,wBAAwB,wBAAoBC,WAAAA;AACvD,SAAO,CAACC,MAA+BC,aAAaD,CAAAA,MAAMA,uBAAGD,YAAWA;AAC1E,GAFqC;AAI9B,IAAMG,gCAAgC,wBAAoBH,WAAAA;AAC/D,SAAO,CAACC,MAAyCF,sBAAmCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEG,UAAUC;AAChH,GAF6C;AAItC,IAAMC,mCAAmC,wBAAoBN,WAAAA;AAClE,SAAO,CAACC,MACNF,sBAAsCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEM,YAAYF,UAAaG,MAAMC,QAAQR,EAAEM,OAAO;AAC1G,GAHgD;AAKzC,IAAMG,yBAAyB,wBAAoBV,WAAAA;AACxD,SAAO,CAACC,MAA+B,CAACC,aAAaD,CAAAA,MAAMA,uBAAGD,YAAWA;AAC3E,GAFsC;;;ACV/B,IAAMW,oBAAuC;AAW7C,IAAMC,gBAAgBC,sBAAmCF,iBAAAA;;;ACTzD,IAAMG,aAAa,wBAAoBC,UAAAA;AAC5C,SAAO,QAAQA,+BAAuBC,WAAU;AAClD,GAF0B;AASnB,IAAMC,oBAAoB,wBAAoBF,UAAAA;AACnD,SAAOG,aAAaH,KAAAA,KAAUD,WAAWC,KAAAA;AAC3C,GAFiC;;;ACP1B,IAAMI,SAAS,wBAA8BC,YAAAA;AAClD,MAAIA,SAAS;AAEX,UAAM,EAAEC,OAAOC,OAAO,GAAGC,OAAAA,IAAWH;AACpC,WAAOG;EACT;AACF,GANsB;;;ACVf,IAAMC,mBAAqC;;;ACDlD,SAASC,qBAAkC;AAKpC,IAAMC,gBAAgB;AAGtB,IAAMC,WAAW,wBAACC,UAAAA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,cAAcC,OAAeJ,QAAAA;","names":["AsObjectFactory","isObject","isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","isPayloadOfSchemaTypeWithSources","sources","Array","isArray","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","AsTypeFactory","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
|
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'\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'\nimport { WithMeta } from './Meta'\nimport { Payload, WithSources } from './Payload'\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'\nimport { Payload } from './Payload'\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'\nimport { WithMeta } from './Meta'\nimport { Payload } from './Payload'\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'\nimport { Schema, WithSchema } from './Schema'\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 if (typeof value === 'string') {\n return true\n }\n return false\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,SAASA,iBAAiBC,gBAAgB;AAInC,IAAMC,eAAe,wBAACC,UAAAA;AAC3B,MAAIC,SAASD,KAAAA,GAAQ;AACnB,WAAO,OAAOA,MAAME,WAAW;EACjC;AACA,SAAO;AACT,GAL4B;AAOrB,IAAMC,eAAeC,gBAAgBC,OAAON,YAAAA;AAE5C,IAAMO,YACX,wBAAoBJ,WACpB,CAACF,UAAAA;AACC,MAAID,aAAaC,KAAAA,GAAQ;AACvB,WAAOE,OAAOK,SAASP,MAAME,MAAM;EACrC;AACA,SAAO;AACT,GANA;AAQK,IAAMM,YAAY,wBAAoBN,WAAqBE,gBAAgBC,OAAO,CAACL,UAA+BM,UAAUJ,MAAAA,EAAQF,KAAAA,CAAAA,GAAlH;;;AClBlB,IAAMS,wBAAwB,wBAAoBC,WAAAA;AACvD,SAAO,CAACC,MAA+BC,aAAaD,CAAAA,MAAMA,uBAAGD,YAAWA;AAC1E,GAFqC;AAI9B,IAAMG,gCAAgC,wBAAoBH,WAAAA;AAC/D,SAAO,CAACC,MAAyCF,sBAAmCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEG,UAAUC;AAChH,GAF6C;AAItC,IAAMC,mCAAmC,wBAAoBN,WAAAA;AAClE,SAAO,CAACC,MACNF,sBAAsCC,MAAAA,EAAQC,CAAAA,KAAMA,EAAEM,YAAYF,UAAaG,MAAMC,QAAQR,EAAEM,OAAO;AAC1G,GAHgD;AAKzC,IAAMG,yBAAyB,wBAAoBV,WAAAA;AACxD,SAAO,CAACC,MAA+B,CAACC,aAAaD,CAAAA,MAAMA,uBAAGD,YAAWA;AAC3E,GAFsC;;;ACV/B,IAAMW,oBAAuC;AAW7C,IAAMC,gBAAgBC,sBAAmCF,iBAAAA;;;ACTzD,IAAMG,aAAa,wBAAoBC,UAAAA;AAC5C,SAAO,QAAQA,+BAAuBC,WAAU;AAClD,GAF0B;AASnB,IAAMC,oBAAoB,wBAAoBF,UAAAA;AACnD,SAAOG,aAAaH,KAAAA,KAAUD,WAAWC,KAAAA;AAC3C,GAFiC;;;ACP1B,IAAMI,SAAS,wBAA8BC,YAAAA;AAClD,MAAIA,SAAS;AAEX,UAAM,EAAEC,OAAOC,OAAO,GAAGC,OAAAA,IAAWH;AACpC,WAAOG;EACT;AACF,GANsB;;;ACVf,IAAMC,mBAAqC;;;ACDlD,SAASC,qBAAkC;AAKpC,IAAMC,gBAAgB;AAGtB,IAAMC,WAAW,wBAACC,UAAAA;AACvB,MAAI,OAAOA,UAAU,UAAU;AAC7B,WAAO;EACT;AACA,SAAO;AACT,GALwB;AAOjB,IAAMC,WAAWC,cAAcC,OAAeJ,QAAAA;","names":["AsObjectFactory","isObject","isAnyPayload","value","isObject","schema","asAnyPayload","AsObjectFactory","create","isPayload","includes","asPayload","isPayloadOfSchemaType","schema","x","isAnyPayload","isPayloadOfSchemaTypeWithMeta","$hash","undefined","isPayloadOfSchemaTypeWithSources","sources","Array","isArray","notPayloadOfSchemaType","ModuleErrorSchema","isModuleError","isPayloadOfSchemaType","isWithHash","value","$hash","isPayloadWithHash","isAnyPayload","unMeta","payload","$meta","$hash","result","PayloadSetSchema","AsTypeFactory","PayloadSchema","isSchema","value","asSchema","AsTypeFactory","create"]}
|
package/package.json
CHANGED
package/src/Schema.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { AsTypeFactory, EmptyObject } from '@xylabs/object'
|
|
|
3
3
|
/** Schema type in Javascript is a string */
|
|
4
4
|
export type Schema = string
|
|
5
5
|
|
|
6
|
-
export const PayloadSchema = 'network.xyo.payload'
|
|
6
|
+
export const PayloadSchema = 'network.xyo.payload' as const
|
|
7
7
|
export type PayloadSchema = typeof PayloadSchema
|
|
8
8
|
|
|
9
9
|
export const isSchema = (value: unknown): value is Schema => {
|