@opencrvs/toolkit
Advanced tools
Comparing version 0.0.7-events to 0.0.7-scopes
@@ -110,10 +110,2 @@ import { z } from 'zod'; | ||
export type DeclareActionInput = z.infer<typeof DeclareActionInput>; | ||
/** | ||
* ActionInput types are used to validate the input data for the action. | ||
* In our use case, we use it directly with TRPC to validate the input data for the action. | ||
* using z.literal(ActionType.ACTION).default(ActionType.ACTION) makes them more convenient to use | ||
* without having to pass the type in the input data, when it's defined in the method. | ||
* | ||
* e.g. mutation.declare({createdAt: new Date()}) vs mutation.declare({createdAt: new Date(), type: 'DECLARE'}) | ||
*/ | ||
export declare const ActionInput: z.ZodDiscriminatedUnion<"type", [z.ZodObject<z.objectUtil.extendShape<{ | ||
@@ -120,0 +112,0 @@ eventId: z.ZodString; |
import { z } from 'zod'; | ||
export declare const EventIndex: z.ZodObject<z.objectUtil.extendShape<{ | ||
export declare const EventIndex: z.ZodObject<{ | ||
id: z.ZodString; | ||
@@ -19,9 +19,8 @@ type: z.ZodString; | ||
updatedBy: z.ZodString; | ||
}, { | ||
data: z.ZodRecord<z.ZodString, z.ZodAny>; | ||
}>, "strip", z.ZodTypeAny, { | ||
data: z.ZodRecord<z.ZodString, z.ZodUnknown>; | ||
}, "strip", z.ZodTypeAny, { | ||
type: string; | ||
id: string; | ||
status: "CERTIFIED" | "DECLARED" | "REGISTERED" | "DRAFT" | "CREATED" | "NOTIFIED"; | ||
data: Record<string, any>; | ||
data: Record<string, unknown>; | ||
createdAt: string; | ||
@@ -37,3 +36,3 @@ createdBy: string; | ||
status: "CERTIFIED" | "DECLARED" | "REGISTERED" | "DRAFT" | "CREATED" | "NOTIFIED"; | ||
data: Record<string, any>; | ||
data: Record<string, unknown>; | ||
createdAt: string; | ||
@@ -47,2 +46,43 @@ createdBy: string; | ||
export type EventIndex = z.infer<typeof EventIndex>; | ||
export declare const EventIndices: z.ZodArray<z.ZodObject<{ | ||
id: z.ZodString; | ||
type: z.ZodString; | ||
status: z.ZodNativeEnum<{ | ||
readonly CREATED: "CREATED"; | ||
readonly DRAFT: "DRAFT"; | ||
readonly NOTIFIED: "NOTIFIED"; | ||
readonly DECLARED: "DECLARED"; | ||
readonly REGISTERED: "REGISTERED"; | ||
readonly CERTIFIED: "CERTIFIED"; | ||
}>; | ||
createdAt: z.ZodString; | ||
createdBy: z.ZodString; | ||
createdAtLocation: z.ZodString; | ||
modifiedAt: z.ZodString; | ||
assignedTo: z.ZodNullable<z.ZodString>; | ||
updatedBy: z.ZodString; | ||
data: z.ZodRecord<z.ZodString, z.ZodUnknown>; | ||
}, "strip", z.ZodTypeAny, { | ||
type: string; | ||
id: string; | ||
status: "CERTIFIED" | "DECLARED" | "REGISTERED" | "DRAFT" | "CREATED" | "NOTIFIED"; | ||
data: Record<string, unknown>; | ||
createdAt: string; | ||
createdBy: string; | ||
createdAtLocation: string; | ||
assignedTo: string | null; | ||
modifiedAt: string; | ||
updatedBy: string; | ||
}, { | ||
type: string; | ||
id: string; | ||
status: "CERTIFIED" | "DECLARED" | "REGISTERED" | "DRAFT" | "CREATED" | "NOTIFIED"; | ||
data: Record<string, unknown>; | ||
createdAt: string; | ||
createdBy: string; | ||
createdAtLocation: string; | ||
assignedTo: string | null; | ||
modifiedAt: string; | ||
updatedBy: string; | ||
}>, "many">; | ||
//# sourceMappingURL=EventIndex.d.ts.map |
import { z } from 'zod'; | ||
export declare const ConditionalTypes: { | ||
readonly SHOW: "SHOW"; | ||
readonly ENABLE: "ENABLE"; | ||
}; | ||
export type ConditionalTypes = (typeof ConditionalTypes)[keyof typeof ConditionalTypes]; | ||
declare const BaseField: z.ZodObject<{ | ||
@@ -167,12 +162,2 @@ id: z.ZodString; | ||
export type BaseField = z.infer<typeof BaseField>; | ||
export declare const FieldType: { | ||
readonly TEXT: "TEXT"; | ||
readonly DATE: "DATE"; | ||
readonly PARAGRAPH: "PARAGRAPH"; | ||
readonly RADIO_GROUP: "RADIO_GROUP"; | ||
readonly FILE: "FILE"; | ||
readonly HIDDEN: "HIDDEN"; | ||
}; | ||
export declare const fieldTypes: ("TEXT" | "DATE" | "PARAGRAPH" | "RADIO_GROUP" | "FILE" | "HIDDEN")[]; | ||
export type FieldType = (typeof fieldTypes)[number]; | ||
export declare const FieldConfig: z.ZodDiscriminatedUnion<"type", [z.ZodObject<z.objectUtil.extendShape<{ | ||
@@ -1237,2 +1222,3 @@ id: z.ZodString; | ||
export type FieldConfig = z.infer<typeof FieldConfig>; | ||
export type FieldType = FieldConfig['type']; | ||
export type FieldProps<T extends FieldType> = Extract<FieldConfig, { | ||
@@ -1239,0 +1225,0 @@ type: T; |
@@ -15,4 +15,2 @@ export * from './ActionConfig'; | ||
export * from './state'; | ||
export * from './utils'; | ||
export * from './defineConfig'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -28,3 +28,2 @@ "use strict"; | ||
ActionType: () => ActionType, | ||
ConditionalTypes: () => ConditionalTypes, | ||
DeclareActionInput: () => DeclareActionInput, | ||
@@ -35,2 +34,3 @@ DraftActionInput: () => DraftActionInput, | ||
EventIndex: () => EventIndex, | ||
EventIndices: () => EventIndices, | ||
EventInput: () => EventInput, | ||
@@ -41,3 +41,2 @@ EventMetadata: () => EventMetadata, | ||
FieldConfig: () => FieldConfig, | ||
FieldType: () => FieldType, | ||
FormConfig: () => FormConfig, | ||
@@ -54,7 +53,3 @@ NotifyActionInput: () => NotifyActionInput, | ||
eventStatuses: () => eventStatuses, | ||
fieldTypes: () => fieldTypes, | ||
findPageFields: () => findPageFields, | ||
getCurrentEventState: () => getCurrentEventState, | ||
resolveFieldLabels: () => resolveFieldLabels, | ||
resolveLabelsFromKnownFields: () => resolveLabelsFromKnownFields | ||
getCurrentEventState: () => getCurrentEventState | ||
}); | ||
@@ -91,13 +86,9 @@ module.exports = __toCommonJS(events_exports); | ||
// ../commons/src/events/FieldConfig.ts | ||
var ConditionalTypes = { | ||
SHOW: "SHOW", | ||
ENABLE: "ENABLE" | ||
}; | ||
var FieldId = import_zod3.z.string(); | ||
var ShowConditional = import_zod3.z.object({ | ||
type: import_zod3.z.literal(ConditionalTypes.SHOW), | ||
type: import_zod3.z.literal("SHOW"), | ||
conditional: Conditional() | ||
}); | ||
var EnableConditional = import_zod3.z.object({ | ||
type: import_zod3.z.literal(ConditionalTypes.ENABLE), | ||
type: import_zod3.z.literal("ENABLE"), | ||
conditional: Conditional() | ||
@@ -131,13 +122,4 @@ }); | ||
}); | ||
var FieldType = { | ||
TEXT: "TEXT", | ||
DATE: "DATE", | ||
PARAGRAPH: "PARAGRAPH", | ||
RADIO_GROUP: "RADIO_GROUP", | ||
FILE: "FILE", | ||
HIDDEN: "HIDDEN" | ||
}; | ||
var fieldTypes = Object.values(FieldType); | ||
var TextField = BaseField.extend({ | ||
type: import_zod3.z.literal(FieldType.TEXT), | ||
type: import_zod3.z.literal("TEXT"), | ||
options: import_zod3.z.object({ | ||
@@ -148,3 +130,3 @@ maxLength: import_zod3.z.number().optional().describe("Maximum length of the text") | ||
var DateField = BaseField.extend({ | ||
type: import_zod3.z.literal(FieldType.DATE), | ||
type: import_zod3.z.literal("DATE"), | ||
options: import_zod3.z.object({ | ||
@@ -157,3 +139,3 @@ notice: TranslationConfig.describe( | ||
var Paragraph = BaseField.extend({ | ||
type: import_zod3.z.literal(FieldType.PARAGRAPH), | ||
type: import_zod3.z.literal("PARAGRAPH"), | ||
options: import_zod3.z.object({ | ||
@@ -164,9 +146,9 @@ fontVariant: import_zod3.z.literal("reg16").optional() | ||
var File = BaseField.extend({ | ||
type: import_zod3.z.literal(FieldType.FILE) | ||
type: import_zod3.z.literal("FILE") | ||
}).describe("File upload"); | ||
var Hidden = BaseField.extend({ | ||
type: import_zod3.z.literal(FieldType.HIDDEN) | ||
type: import_zod3.z.literal("HIDDEN") | ||
}).describe("Hidden field"); | ||
var RadioGroup = BaseField.extend({ | ||
type: import_zod3.z.literal(FieldType.RADIO_GROUP), | ||
type: import_zod3.z.literal("RADIO_GROUP"), | ||
options: import_zod3.z.array( | ||
@@ -280,2 +262,5 @@ import_zod3.z.object({ | ||
// ../commons/src/events/EventConfig.ts | ||
var import_lodash = require("lodash"); | ||
// ../commons/src/events/WorkqueueConfig.ts | ||
@@ -385,2 +370,59 @@ var import_zod8 = require("zod"); | ||
}); | ||
var findPageFields = (config) => { | ||
return (0, import_lodash.flattenDeep)( | ||
config.actions.map( | ||
({ forms }) => forms.map( | ||
({ pages }) => pages.map( | ||
({ fields }) => fields.map((field) => ({ id: field.id, label: field.label })) | ||
) | ||
) | ||
) | ||
); | ||
}; | ||
var fillFieldLabels = ({ | ||
pageFields, | ||
refFields | ||
}) => { | ||
return refFields.map((field) => { | ||
if (field.label) { | ||
return field; | ||
} | ||
const metadataLabel = eventMetadataLabelMap[field.id]; | ||
if (metadataLabel) { | ||
return { | ||
...field, | ||
label: metadataLabel | ||
}; | ||
} | ||
const pageLabel = pageFields.find((pageField) => pageField.id === field.id); | ||
if (!pageLabel) { | ||
throw new Error(`Referenced field ${field.id} does not have a label`); | ||
} | ||
return { | ||
...field, | ||
label: pageLabel.label | ||
}; | ||
}); | ||
}; | ||
var defineConfig = (config) => { | ||
const parsed = EventConfig.parse(config); | ||
const pageFields = findPageFields(parsed); | ||
return EventConfig.parse({ | ||
...parsed, | ||
summary: { | ||
...parsed.summary, | ||
fields: fillFieldLabels({ | ||
pageFields, | ||
refFields: parsed.summary.fields | ||
}) | ||
}, | ||
workqueues: parsed.workqueues.map((workqueue) => ({ | ||
...workqueue, | ||
fields: fillFieldLabels({ | ||
pageFields, | ||
refFields: workqueue.fields | ||
}) | ||
})) | ||
}); | ||
}; | ||
var defineForm = (form) => FormConfig.parse(form); | ||
@@ -546,5 +588,15 @@ | ||
var import_zod14 = require("zod"); | ||
var EventIndex = EventMetadata.extend({ | ||
data: import_zod14.z.record(import_zod14.z.string(), import_zod14.z.any()) | ||
var EventIndex = import_zod14.z.object({ | ||
id: import_zod14.z.string(), | ||
type: import_zod14.z.string(), | ||
status: EventStatuses, | ||
createdAt: import_zod14.z.string().datetime(), | ||
createdBy: import_zod14.z.string(), | ||
createdAtLocation: import_zod14.z.string(), | ||
modifiedAt: import_zod14.z.string().datetime(), | ||
assignedTo: import_zod14.z.string().nullable(), | ||
updatedBy: import_zod14.z.string(), | ||
data: import_zod14.z.record(import_zod14.z.string(), import_zod14.z.unknown()) | ||
}); | ||
var EventIndices = import_zod14.z.array(EventIndex); | ||
@@ -554,23 +606,23 @@ // ../commons/src/events/state/index.ts | ||
return actions.reduce((status, action) => { | ||
if (action.type === ActionType.CREATE) { | ||
return EventStatus.CREATED; | ||
if (action.type === "CREATE") { | ||
return "CREATED"; | ||
} | ||
if (action.type === ActionType.DECLARE) { | ||
return EventStatus.DECLARED; | ||
if (action.type === "DECLARE") { | ||
return "DECLARED"; | ||
} | ||
if (action.type === ActionType.DRAFT) { | ||
return EventStatus.DRAFT; | ||
if (action.type === "DRAFT") { | ||
return "DRAFT"; | ||
} | ||
if (action.type === ActionType.REGISTER) { | ||
return EventStatus.REGISTERED; | ||
if (action.type === "REGISTER") { | ||
return "REGISTERED"; | ||
} | ||
return status; | ||
}, EventStatus.CREATED); | ||
}, "CREATED"); | ||
} | ||
function getAssignedUserFromActions(actions) { | ||
return actions.reduce((status, action) => { | ||
if (action.type === ActionType.ASSIGN) { | ||
if (action.type === "ASSIGN") { | ||
return action.assignedTo; | ||
} | ||
if (action.type === ActionType.UNASSIGN) { | ||
if (action.type === "UNASSIGN") { | ||
return null; | ||
@@ -591,7 +643,4 @@ } | ||
const creationAction = event.actions.find( | ||
(action) => action.type === ActionType.CREATE | ||
(action) => action.type === "CREATE" | ||
); | ||
if (!creationAction) { | ||
throw new Error(`Event ${event.id} has no creation action`); | ||
} | ||
const latestAction = event.actions[event.actions.length - 1]; | ||
@@ -611,74 +660,1 @@ return { | ||
} | ||
// ../commons/src/events/utils.ts | ||
var import_lodash = require("lodash"); | ||
var isMetadataField = (field) => field in eventMetadataLabelMap; | ||
var findPageFields = (config) => { | ||
return (0, import_lodash.flattenDeep)( | ||
config.actions.map( | ||
({ forms }) => forms.map( | ||
({ pages }) => pages.map( | ||
({ fields }) => fields.map((field) => ({ | ||
id: field.id, | ||
label: field.label | ||
})) | ||
) | ||
) | ||
) | ||
); | ||
}; | ||
var resolveLabelsFromKnownFields = ({ | ||
pageFields, | ||
refFields | ||
}) => { | ||
return refFields.map((field) => { | ||
if (field.label) { | ||
return field; | ||
} | ||
if (isMetadataField(field.id)) { | ||
return { | ||
...field, | ||
label: eventMetadataLabelMap[field.id] | ||
}; | ||
} | ||
const pageLabel = pageFields.find((pageField) => pageField.id === field.id); | ||
if (!pageLabel) { | ||
throw new Error(`Referenced field ${field.id} does not have a label`); | ||
} | ||
return { | ||
...field, | ||
label: pageLabel.label | ||
}; | ||
}); | ||
}; | ||
var resolveFieldLabels = ({ | ||
config, | ||
pageFields | ||
}) => { | ||
return { | ||
...config, | ||
fields: resolveLabelsFromKnownFields({ | ||
pageFields, | ||
refFields: config.fields | ||
}) | ||
}; | ||
}; | ||
// ../commons/src/events/defineConfig.ts | ||
var defineConfig = (config) => { | ||
const parsed = EventConfig.parse(config); | ||
const pageFields = findPageFields(parsed); | ||
return EventConfig.parse({ | ||
...parsed, | ||
summary: resolveFieldLabels({ | ||
config: parsed.summary, | ||
pageFields | ||
}), | ||
workqueues: parsed.workqueues.map( | ||
(workqueue) => resolveFieldLabels({ | ||
config: workqueue, | ||
pageFields | ||
}) | ||
) | ||
}); | ||
}; |
@@ -102,3 +102,2 @@ import { z } from 'zod'; | ||
export type WorkqueueConfig = z.infer<typeof WorkqueueConfig>; | ||
export type WorkqueueConfigInput = z.input<typeof WorkqueueConfig>; | ||
//# sourceMappingURL=WorkqueueConfig.d.ts.map |
{ | ||
"name": "@opencrvs/toolkit", | ||
"version": "0.0.7-events", | ||
"version": "0.0.7-scopes", | ||
"description": "OpenCRVS toolkit for building country configurations", | ||
@@ -9,9 +9,12 @@ "license": "MPL-2.0", | ||
"./events": "./dist/events/index.js", | ||
"./scopes": "./dist/scopes/index.js", | ||
"./conditionals": "./dist/conditionals/index.js" | ||
}, | ||
"scripts": { | ||
"build": "rimraf dist && tsc --build && yarn build-common-events:js && yarn copy-common-events:ts && yarn build-common-conditionals:js && yarn copy-common-conditionals:ts", | ||
"build": "rimraf dist && tsc --build && yarn build-common-events:js && yarn copy-common-events:ts && yarn build-common-scopes:js && yarn copy-common-scopes:ts && yarn build-common-conditionals:js && yarn copy-common-conditionals:ts", | ||
"build-common-events:js": "esbuild src/events/index.ts --bundle --format=cjs --outdir=./dist/events --allow-overwrite --packages=external", | ||
"build-common-scopes:js": "esbuild src/events/index.ts --bundle --format=cjs --outdir=./dist/scopes --allow-overwrite --packages=external", | ||
"build-common-conditionals:js": "esbuild src/conditionals/index.ts --bundle --format=cjs --outdir=./dist/conditionals --allow-overwrite --packages=external", | ||
"copy-common-events:ts": "cp -r ../commons/build/dist/common/events/*.d.ts ./dist/events", | ||
"copy-common-scopes:ts": "cp -r ../commons/build/dist/common/scopes.d.ts ./dist/scopes/index.d.ts", | ||
"copy-common-conditionals:ts": "cp -r ../commons/build/dist/common/conditionals/*.d.ts ./dist/conditionals" | ||
@@ -27,4 +30,5 @@ }, | ||
"moduleNameMapper": { | ||
"@opencrvs/commons/events": "@opencrvs/commons/build/dist/common/events/index.js" | ||
"@opencrvs/commons/events": "@opencrvs/commons/build/dist/common/events/index.js", | ||
"@opencrvs/commons/scopes": "@opencrvs/commons/build/dist/common/scopes.js" | ||
} | ||
} |
@@ -10,2 +10,3 @@ # OpenCRVS toolkit | ||
events/ # re-exports events module from commons package | ||
scopes/ # re-exports scopes module from commons package | ||
lib.ts # standard library. currently empty | ||
@@ -44,2 +45,2 @@ ``` | ||
- Package is published and should be used without knowledge of rest of the monorepo | ||
- Package exposes `/events` directory, with types, from `packages/commons` through the library, others are excluded. | ||
- Package exposes `/events, /scopes` directory, with types, from `packages/commons` through the library, others are excluded. |
@@ -18,2 +18,3 @@ { | ||
], | ||
"@opencrvs/commons/scopes": ["../commons/src/scopes.ts"], | ||
"@opencrvs/commons/events": ["../commons/src/events/index.ts"] | ||
@@ -20,0 +21,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1632842
31
41598
45