@protobase/schema 0.48.0 → 0.49.1

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/index.d.ts CHANGED
@@ -7,6 +7,7 @@ import { AnyField, Constraint, Field, FieldMeta, FieldTypeDef } from "./field.js
7
7
  import { RelationField } from "./relation-field.js";
8
8
  import { FileField } from "./file-field.js";
9
9
  import { f } from "./fields.js";
10
+ import { ArgumentSpec, ArgumentType, ArgumentsSpec, argumentsSchema } from "./job-arguments.js";
10
11
  import { ComputedReveal, RevealCaller } from "./computed/computed-reveal.js";
11
12
  import { FieldRefs, FieldsInput, Ref, Refs } from "./refs.js";
12
13
  import { CreatedOptions, DeletedOptions, EventActor, EventContext, EventHelpers, EventMatch, EventSpec, UndeletedOptions, UpdatedOptions } from "./events/event-helpers.js";
@@ -46,4 +47,4 @@ import { AccessSource, ResolveOptions, ResolvedAccess, RowFilterOperation, acces
46
47
  import { restrictModel } from "./access/restrict.js";
47
48
  import "./access/index.js";
48
49
  import { AssistantAction, AssistantActionRequest, AssistantCardPart, AssistantDiff, AssistantEvent, AssistantMessage, AssistantMessageRequest, AssistantPart, AssistantState, AssistantStep, AssistantStepState, AssistantTablePart, AssistantTextPart, AssistantTone, AssistantWidgetPart } from "./assistant/protocol.js";
49
- export { type Access, type AccessAction, type AccessContext, type AccessFn, type AccessResult, type AccessSource, type AccessUser, type ActionInputKind, type ActionInputModel, type ActionModel, type ActionRun, type AnyField, type AppAddress, type AssistantAction, type AssistantActionRequest, type AssistantCardPart, type AssistantDiff, type AssistantEvent, type AssistantMessage, type AssistantMessageRequest, type AssistantPart, type AssistantState, type AssistantStep, type AssistantStepState, type AssistantTablePart, type AssistantTextPart, type AssistantTone, type AssistantWidgetPart, type BadgeShape, type BottomBarItemModel, type BottomBarModel, type BottomBarNames, type BottomBarSource, type CalendarView, type Capability, type CapabilityAction, type CapabilityLimit, type CapabilityScope, type CardFavoriteModel, type CardPhotosModel, type ChartGranularity, type ChartInput, type ChartModel, type ChartRange, type CheckResult, type CheckedFilter, type CommentsSectionModel, type CompareOp, type ComponentRef, type ComputedReveal, type ConnectAddress, type Constraint, type CreateModel, type CreatedOptions, type CustomSectionModel, type DatePreset, type DeletedOptions, type DurationLiteral, type DurationUnit, type Encrypted, type EvaluateOptions, type EventActor, type EventContext, type EventHelpers, type EventMatch, type EventModel, type EventOperation, type EventSpec, type ExactCapability, type ExportModel, type Field, type FieldAccess, type FieldFormat, type FieldMeta, type FieldModel, type FieldPath, type FieldRefValue, type FieldRefs, type FieldRule, type FieldType, type FieldTypeDef, type FieldView, type FieldViewModel, type FieldViews, type FieldWidgetModel, type FieldsInput, type FileField, type FileFieldModel, type FileOptions, type FileProcessor, type FileProcessorInput, type FilterError, type FilterErrorCode, type FilterExpr, type FilterLayout, type FilterLimits, type FilterOf, type FilterParse, type FilterValue, type FilterWidgetModel, type FormAddress, type FormInput, type FormModel, type GalleryModel, type Grant, type GroupChartInput, type GroupChartModel, type GroupItemModel, type GroupModel, type HeldCapability, type HelpWhen, type HistorySectionModel, type ImageFormat, type ImageVariant, type ImageVariantOptions, type InferRecord, type Issue, type JsonValue, type KeyOf, type KeyRefs, type KeyType, type KeyValue, type LayoutItemModel, type ListColumn, type ListDisplayModel, type ListDragModel, type ListModel, type ListQuery, type Literal, type MapSectionModel, type MapView, type NamedListModel, type NavModel, type NavRecentModel, type NowValue, type OrderByCheck, type OrderByItem, type OrderByParse, type ParentAccess, type ParentModel, type PeriodChartInput, type PeriodChartModel, type PositionAfterModel, type RecordChartModel, type RecordChartRange, type RecordKey, type RecordMode, type RecordOf, type RecordWhen, type Ref, type Refs, type RelatedColumnModel, type RelatedModel, type RelatedPresentation, type RelationField, type ResolveOptions, type ResolvedAccess, type ResourceBuilder, type ResourceModel, type RevealCaller, type RoleEntry, type RoleLimit, type Roles, type RolesOptions, type Rollup, type RollupCount, type RollupFn, type RollupSource, type RollupValue, type RowFilterOperation, type Rule, type SaveFeedback, type SaveSearchModel, type SearchMatch, type SearchRef, type SearchRefs, type SearchResultModel, type SearchesOfModel, type SectionModel, type SectionPresentation, type ShowWhen, type SignInAddress, type SignInPromptModel, type SignInStep, type SignInViewModel, type SortSpec, type Span, type StatusTone, type TabItemModel, type TabModel, type TenantOptions, type TimelineView, type UndeletedOptions, type UpdatedOptions, type UserMenuItemModel, type UserMenuModel, type UserMenuSource, type Validator, type ViewBuilder, type ViewModel, type ViewProps, accessWarnings, addressWords, anonymousRole, appPath, bottomBar, bottomBarErrors, checkFilter, checkOrderBy, checkRecord, connectParams, connectPath, connectRoute, createWhere, defineRoles, encrypted, enumLabel, evaluateFilter, f, fieldRef, fieldsUsedBy, fitsKeyType, formPath, formRoute, imageFormats, isRecordCondition, keyTypes, layout as l, maxBottomBarItems, parseFilter, parseOrderBy, pickView, printFilter, printOrderBy, readAppPath, readConnectAddress, readFormAddress, readSignInAddress, resolveAccess, resource, restrictModel, rule, signInParams, signInPath, signInRoute, signInSteps, userMenu, view, where };
50
+ export { type Access, type AccessAction, type AccessContext, type AccessFn, type AccessResult, type AccessSource, type AccessUser, type ActionInputKind, type ActionInputModel, type ActionModel, type ActionRun, type AnyField, type AppAddress, type ArgumentSpec, type ArgumentType, type ArgumentsSpec, type AssistantAction, type AssistantActionRequest, type AssistantCardPart, type AssistantDiff, type AssistantEvent, type AssistantMessage, type AssistantMessageRequest, type AssistantPart, type AssistantState, type AssistantStep, type AssistantStepState, type AssistantTablePart, type AssistantTextPart, type AssistantTone, type AssistantWidgetPart, type BadgeShape, type BottomBarItemModel, type BottomBarModel, type BottomBarNames, type BottomBarSource, type CalendarView, type Capability, type CapabilityAction, type CapabilityLimit, type CapabilityScope, type CardFavoriteModel, type CardPhotosModel, type ChartGranularity, type ChartInput, type ChartModel, type ChartRange, type CheckResult, type CheckedFilter, type CommentsSectionModel, type CompareOp, type ComponentRef, type ComputedReveal, type ConnectAddress, type Constraint, type CreateModel, type CreatedOptions, type CustomSectionModel, type DatePreset, type DeletedOptions, type DurationLiteral, type DurationUnit, type Encrypted, type EvaluateOptions, type EventActor, type EventContext, type EventHelpers, type EventMatch, type EventModel, type EventOperation, type EventSpec, type ExactCapability, type ExportModel, type Field, type FieldAccess, type FieldFormat, type FieldMeta, type FieldModel, type FieldPath, type FieldRefValue, type FieldRefs, type FieldRule, type FieldType, type FieldTypeDef, type FieldView, type FieldViewModel, type FieldViews, type FieldWidgetModel, type FieldsInput, type FileField, type FileFieldModel, type FileOptions, type FileProcessor, type FileProcessorInput, type FilterError, type FilterErrorCode, type FilterExpr, type FilterLayout, type FilterLimits, type FilterOf, type FilterParse, type FilterValue, type FilterWidgetModel, type FormAddress, type FormInput, type FormModel, type GalleryModel, type Grant, type GroupChartInput, type GroupChartModel, type GroupItemModel, type GroupModel, type HeldCapability, type HelpWhen, type HistorySectionModel, type ImageFormat, type ImageVariant, type ImageVariantOptions, type InferRecord, type Issue, type JsonValue, type KeyOf, type KeyRefs, type KeyType, type KeyValue, type LayoutItemModel, type ListColumn, type ListDisplayModel, type ListDragModel, type ListModel, type ListQuery, type Literal, type MapSectionModel, type MapView, type NamedListModel, type NavModel, type NavRecentModel, type NowValue, type OrderByCheck, type OrderByItem, type OrderByParse, type ParentAccess, type ParentModel, type PeriodChartInput, type PeriodChartModel, type PositionAfterModel, type RecordChartModel, type RecordChartRange, type RecordKey, type RecordMode, type RecordOf, type RecordWhen, type Ref, type Refs, type RelatedColumnModel, type RelatedModel, type RelatedPresentation, type RelationField, type ResolveOptions, type ResolvedAccess, type ResourceBuilder, type ResourceModel, type RevealCaller, type RoleEntry, type RoleLimit, type Roles, type RolesOptions, type Rollup, type RollupCount, type RollupFn, type RollupSource, type RollupValue, type RowFilterOperation, type Rule, type SaveFeedback, type SaveSearchModel, type SearchMatch, type SearchRef, type SearchRefs, type SearchResultModel, type SearchesOfModel, type SectionModel, type SectionPresentation, type ShowWhen, type SignInAddress, type SignInPromptModel, type SignInStep, type SignInViewModel, type SortSpec, type Span, type StatusTone, type TabItemModel, type TabModel, type TenantOptions, type TimelineView, type UndeletedOptions, type UpdatedOptions, type UserMenuItemModel, type UserMenuModel, type UserMenuSource, type Validator, type ViewBuilder, type ViewModel, type ViewProps, accessWarnings, addressWords, anonymousRole, appPath, argumentsSchema, bottomBar, bottomBarErrors, checkFilter, checkOrderBy, checkRecord, connectParams, connectPath, connectRoute, createWhere, defineRoles, encrypted, enumLabel, evaluateFilter, f, fieldRef, fieldsUsedBy, fitsKeyType, formPath, formRoute, imageFormats, isRecordCondition, keyTypes, layout as l, maxBottomBarItems, parseFilter, parseOrderBy, pickView, printFilter, printOrderBy, readAppPath, readConnectAddress, readFormAddress, readSignInAddress, resolveAccess, resource, restrictModel, rule, signInParams, signInPath, signInRoute, signInSteps, userMenu, view, where };
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { imageFormats } from "./files/file-options.js";
2
2
  import { f } from "./fields.js";
3
+ import { argumentsSchema } from "./job-arguments.js";
3
4
  import { parseFilter } from "./filter/parse.js";
4
5
  import { checkFilter } from "./filter/check.js";
5
6
  import { evaluateFilter } from "./filter/evaluate.js";
@@ -27,4 +28,4 @@ import { rule } from "./access/rule.js";
27
28
  import { defineRoles } from "./access/roles.js";
28
29
  import { pickView } from "./access/pick-view.js";
29
30
  import { restrictModel } from "./access/restrict.js";
30
- export { accessWarnings, addressWords, anonymousRole, appPath, bottomBar, bottomBarErrors, checkFilter, checkOrderBy, checkRecord, connectParams, connectPath, connectRoute, createWhere, defineRoles, encrypted, enumLabel, evaluateFilter, f, fieldRef, fieldsUsedBy, fitsKeyType, formPath, formRoute, imageFormats, isRecordCondition, keyTypes, layout as l, maxBottomBarItems, parseFilter, parseOrderBy, pickView, printFilter, printOrderBy, readAppPath, readConnectAddress, readFormAddress, readSignInAddress, resolveAccess, resource, restrictModel, rule, signInParams, signInPath, signInRoute, signInSteps, userMenu, view, where };
31
+ export { accessWarnings, addressWords, anonymousRole, appPath, argumentsSchema, bottomBar, bottomBarErrors, checkFilter, checkOrderBy, checkRecord, connectParams, connectPath, connectRoute, createWhere, defineRoles, encrypted, enumLabel, evaluateFilter, f, fieldRef, fieldsUsedBy, fitsKeyType, formPath, formRoute, imageFormats, isRecordCondition, keyTypes, layout as l, maxBottomBarItems, parseFilter, parseOrderBy, pickView, printFilter, printOrderBy, readAppPath, readConnectAddress, readFormAddress, readSignInAddress, resolveAccess, resource, restrictModel, rule, signInParams, signInPath, signInRoute, signInSteps, userMenu, view, where };
@@ -0,0 +1,36 @@
1
+ import { z } from "zod";
2
+ //#region src/job-arguments.d.ts
3
+ /** The type of a job's argument: one of the field types, each holding the value a record's field of that type holds. */
4
+ export type ArgumentType = 'text' | 'integer' | 'bigint' | 'decimal' | 'boolean' | 'date' | 'timestamp' | 'uuid' | 'enum' | 'json' | 'currency' | 'country';
5
+ /**
6
+ * One argument of a job, as plain data: its type, such as `'bigint'`, or the type with its options, such as
7
+ * `{ type: 'enum', values: ['day', 'week'] }`, `{ type: 'integer', min: 1, optional: true }` or
8
+ * `{ type: 'decimal', precision: 8, scale: 2 }`. A value is checked as a field of that type checks it.
9
+ */
10
+ export type ArgumentSpec = ArgumentType | {
11
+ /** The argument's type. */
12
+ type: ArgumentType;
13
+ /** It may be left out. */
14
+ optional?: boolean;
15
+ /** An enum's values. */
16
+ values?: string[];
17
+ /** The least value, or for text the shortest length. */
18
+ min?: number;
19
+ /** The greatest value, or for text the longest length. */
20
+ max?: number;
21
+ /** A decimal's number of digits. */
22
+ precision?: number;
23
+ /** A decimal's number of digits after the point. */
24
+ scale?: number;
25
+ };
26
+ /** A job's arguments by name. */
27
+ export type ArgumentsSpec = Record<string, ArgumentSpec>;
28
+ /**
29
+ * The schema a job's payload is checked with, from its declared arguments: an object of exactly those arguments, each
30
+ * checked as a field of its type. A Standard Schema, as `defineJob`'s `payload` takes. Throws on an unknown type or an
31
+ * option its type needs, such as a decimal without `precision`, naming the job and the argument.
32
+ */
33
+ export declare const argumentsSchema: (job: string, spec: ArgumentsSpec) => z.ZodObject<{
34
+ [x: string]: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
35
+ }, z.core.$strict>;
36
+ //#endregion
@@ -0,0 +1,57 @@
1
+ import { bigint } from "./fields/bigint.js";
2
+ import { boolean } from "./fields/boolean.js";
3
+ import { country } from "./fields/country.js";
4
+ import { currency } from "./fields/currency.js";
5
+ import { date } from "./fields/date.js";
6
+ import { decimal } from "./fields/decimal.js";
7
+ import { enumeration } from "./fields/enum.js";
8
+ import { integer } from "./fields/integer.js";
9
+ import { json } from "./fields/json.js";
10
+ import { text } from "./fields/text.js";
11
+ import { timestamp } from "./fields/timestamp.js";
12
+ import { uuid } from "./fields/uuid.js";
13
+ import { z } from "zod";
14
+ //#region src/job-arguments.ts
15
+ const argumentTypes = {
16
+ text,
17
+ integer,
18
+ bigint,
19
+ decimal,
20
+ boolean,
21
+ date,
22
+ timestamp,
23
+ uuid,
24
+ enum: enumeration,
25
+ json,
26
+ currency,
27
+ country
28
+ };
29
+ const metaOf = (spec) => ({
30
+ type: spec.type,
31
+ nullable: false,
32
+ readOnly: false,
33
+ filterable: false,
34
+ sortable: false,
35
+ aliases: [],
36
+ hasDefault: false,
37
+ ...spec.values && { enumValues: spec.values },
38
+ ...spec.min !== void 0 && { min: spec.min },
39
+ ...spec.max !== void 0 && { max: spec.max },
40
+ ...spec.precision !== void 0 && { precision: spec.precision },
41
+ ...spec.scale !== void 0 && { scale: spec.scale }
42
+ });
43
+ const argumentSchema = (job, name, given) => {
44
+ const spec = typeof given === "string" ? { type: given } : given;
45
+ const def = argumentTypes[spec.type];
46
+ if (!def) throw new Error(`Job "${job}": argument "${name}" has the type "${spec.type}", which is none of ${Object.keys(argumentTypes).join(", ")}`);
47
+ const schema = def.build(metaOf(spec));
48
+ return spec.optional ? schema.optional() : schema;
49
+ };
50
+ /**
51
+ * The schema a job's payload is checked with, from its declared arguments: an object of exactly those arguments, each
52
+ * checked as a field of its type. A Standard Schema, as `defineJob`'s `payload` takes. Throws on an unknown type or an
53
+ * option its type needs, such as a decimal without `precision`, naming the job and the argument.
54
+ */
55
+ const argumentsSchema = (job, spec) => z.strictObject(Object.fromEntries(Object.entries(spec).map(([name, given]) => [name, argumentSchema(job, name, given)])));
56
+ //#endregion
57
+ export { argumentsSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/schema",
3
- "version": "0.48.0",
3
+ "version": "0.49.1",
4
4
  "description": "Resource, field, view and access definitions for Protobase configs.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {