@vibeorm/runtime 2.0.0-alpha.7 → 2.0.0-alpha.9
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/client.d.ts +24 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1315 -22
- package/dist/index.js.map +9 -6
- package/dist/model-meta.d.ts +7 -0
- package/dist/model-meta.d.ts.map +1 -1
- package/dist/policy.d.ts +40 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/query-builder.d.ts.map +1 -1
- package/dist/scoped.d.ts +131 -0
- package/dist/scoped.d.ts.map +1 -0
- package/dist/validators.d.ts +59 -0
- package/dist/validators.d.ts.map +1 -0
- package/package.json +5 -4
package/dist/model-meta.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export type FieldMeta = {
|
|
|
21
21
|
readonly name: string;
|
|
22
22
|
/** Database column name (`dbName ?? name`). */
|
|
23
23
|
readonly columnName: string;
|
|
24
|
+
/** Explicit column collation (@collation, board #36) — mysql insensitive-filter rendering reads it. */
|
|
25
|
+
readonly collation?: string;
|
|
24
26
|
readonly type: FieldType;
|
|
25
27
|
/** The scalar type, or `null` when the field is an enum reference. */
|
|
26
28
|
readonly scalarType: ScalarType | null;
|
|
@@ -83,6 +85,11 @@ export type ModelMeta = {
|
|
|
83
85
|
readonly relations: readonly RelationIR[];
|
|
84
86
|
readonly relationByName: ReadonlyMap<string, RelationIR>;
|
|
85
87
|
readonly isView: boolean;
|
|
88
|
+
/** Row-scoping policy (@@policy) — the client fails closed on it ($withPolicy). */
|
|
89
|
+
readonly policy?: {
|
|
90
|
+
readonly field: string;
|
|
91
|
+
readonly context: string;
|
|
92
|
+
};
|
|
86
93
|
/** Computed fields configured for this model, or `null` (the common case). */
|
|
87
94
|
readonly computed: ReadonlyMap<string, ComputedFieldMeta> | null;
|
|
88
95
|
};
|
package/dist/model-meta.d.ts.map
CH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AAI,MAAM,CAErC;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAKD,+FAA+F;AAC/F,wBAAgB,cAAc,IAAI,MAAM,CAQvC;AAID;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAcrC;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,GAAG,OAAO,CAmB9E;AA4JD,oEAAoE;AACpE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,EAAE,cAAc,CAAA;CAAE,GAAG,WAAW,CAuBrG;AAID,sFAAsF;AACtF,wBAAgB,YAAY,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAWpF;AAED,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAyBpG"}
|
package/dist/policy.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Policy scoping — `$withPolicy` / `$bypassPolicy` (EPIC 4b).
|
|
3
|
+
*
|
|
4
|
+
* Application-level ROW scoping for models declaring `@@policy`, implemented
|
|
5
|
+
* as an args-rewriting layer over the built delegates (the views.ts pattern:
|
|
6
|
+
* ZERO query-builder edits — every emitted statement is a shape the catalogs
|
|
7
|
+
* already pin). Complements `$defineView` (COLUMN masking) and, on postgres,
|
|
8
|
+
* database RLS (the defense-in-depth backstop; see docs/migrations.md).
|
|
9
|
+
*
|
|
10
|
+
* Semantics:
|
|
11
|
+
* - FAIL CLOSED: on a client whose schema declares any @@policy, the base
|
|
12
|
+
* delegates of policied models refuse every method until the caller binds
|
|
13
|
+
* a context (`$withPolicy({ tenant })`) or bypasses deliberately
|
|
14
|
+
* (`$bypassPolicy()` — explicit and greppable).
|
|
15
|
+
* - Reads AND the policy predicate into `where` (findUnique rewrites to
|
|
16
|
+
* findFirst over the flattened unique key). Policied CHILD models are
|
|
17
|
+
* scoped inside include/select at any depth.
|
|
18
|
+
* - `create`/`createMany` FORCE the context value into the data (a
|
|
19
|
+
* conflicting explicit value is VIBE_VALIDATION). Nested `create` on a
|
|
20
|
+
* policied child is forced too.
|
|
21
|
+
* - `update`/`delete`/`upsert` run as lock-read (FOR UPDATE) + write-by-PK
|
|
22
|
+
* inside one transaction; a cross-context target is VIBE_NOT_FOUND.
|
|
23
|
+
* - Nested verbs REFERENCING existing rows of a policied child (connect,
|
|
24
|
+
* connectOrCreate, set, disconnect, nested update/delete/upsert) are
|
|
25
|
+
* REFUSED from a scoped client in this first cut — fail-closed beats a
|
|
26
|
+
* silent hole. `$queryRaw`/`$executeRaw` are outside policy by design.
|
|
27
|
+
*/
|
|
28
|
+
import type { RuntimeMeta } from "./model-meta.ts";
|
|
29
|
+
import type { DynamicClient } from "./client.ts";
|
|
30
|
+
/** Values a policy context may bind — the scoping column's scalar shape. */
|
|
31
|
+
export type PolicyContextValue = string | number | bigint;
|
|
32
|
+
/**
|
|
33
|
+
* Attach `$withPolicy`/`$bypassPolicy` and fail-close the base delegates of
|
|
34
|
+
* policied models. No-op on schemas without @@policy.
|
|
35
|
+
*/
|
|
36
|
+
export declare function attachPolicy(params: {
|
|
37
|
+
client: DynamicClient;
|
|
38
|
+
meta: RuntimeMeta;
|
|
39
|
+
}): void;
|
|
40
|
+
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,iBA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,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B,GAAG,OAAO,CAqBV;AA0uBD,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAEvE;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAAG,MAAM,EAAE,CAgBrF;AA2mBD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IACzC,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B,GAAG;IACF,SAAS,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACpC,YAAY,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IACvC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;CACpC,CAkBA;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE;IACjC,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,WAAW,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,uBAAuB,CAAC,EAAE,gBAAgB,CAAC;IAC3C,aAAa,CAAC,EAAE,oBAAoB,CAAC;CACtC,GAAG,SAAS,CAunBZ"}
|
package/dist/scoped.d.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tenant scoping — `$scoped` (framework handoff: one scoped handle per request).
|
|
3
|
+
*
|
|
4
|
+
* A CALLER-CONFIGURED row-scoping layer: the base client plus a total
|
|
5
|
+
* per-model tenancy map plus a scope value produce a NEW handle whose every
|
|
6
|
+
* query is structurally confined to that tenant. Complements `@@policy`
|
|
7
|
+
* (schema-declared, fail-closed) — the two do NOT combine: `$scoped` refuses
|
|
8
|
+
* on a client whose schema declares any `@@policy`.
|
|
9
|
+
*
|
|
10
|
+
* Implemented as PURE args rewriting over the built delegates (the views.ts /
|
|
11
|
+
* policy.ts pattern — ZERO query-builder edits; every emitted statement is a
|
|
12
|
+
* shape the catalogs already pin). The rewrite relies on three verified
|
|
13
|
+
* builder properties:
|
|
14
|
+
* 1. findUnique/connect wheres compile their FULL where object — extra
|
|
15
|
+
* fields and `AND` groups become filters (query-builder findUnique,
|
|
16
|
+
* nested-writes resolveTargetKey), so injecting the tenant predicate
|
|
17
|
+
* into a unique where IS the verified lookup, inside whatever
|
|
18
|
+
* transaction the write already runs.
|
|
19
|
+
* 2. A guard field beyond the conflict target forces upsert onto the
|
|
20
|
+
* transactional find-then-write fallback (PG-2), whose probe honors the
|
|
21
|
+
* full where — so an injected upsert can never fire ON CONFLICT against
|
|
22
|
+
* another tenant's row.
|
|
23
|
+
* 3. Cursors compile from caller-supplied values only (no row lookup), so
|
|
24
|
+
* cursor pagination needs no rewrite to stay leak-free.
|
|
25
|
+
*
|
|
26
|
+
* Deny-by-default: every argument node that touches a scoped model either
|
|
27
|
+
* gets the predicate injected where semantics allow, or the call REFUSES with
|
|
28
|
+
* a typed `ScopedQueryError { model, path, reason }` before any SQL runs.
|
|
29
|
+
* Raw SQL is absent from the scoped surface; the deliberate escape is the
|
|
30
|
+
* BASE client, which this layer never mutates.
|
|
31
|
+
*/
|
|
32
|
+
import type { RelationIR } from "@vibeorm/schema";
|
|
33
|
+
import type { FieldMeta, RuntimeMeta } from "./model-meta.ts";
|
|
34
|
+
import type { ClientRow, DynamicClient } from "./client.ts";
|
|
35
|
+
/** Scope values a tenant column can carry (matches String / Int / BigInt columns). */
|
|
36
|
+
export type ScopeValue = string | number | bigint;
|
|
37
|
+
/**
|
|
38
|
+
* What happens when a scoped model appears as a CHILD inside another model's
|
|
39
|
+
* nested write: `"verify"` (default) rewrites reference verbs into
|
|
40
|
+
* tenant-verified lookups; `"refuse"` rejects every reference verb (nested
|
|
41
|
+
* `create` stays allowed under both — it is forced into the tenant).
|
|
42
|
+
*/
|
|
43
|
+
export type ScopedNestedMode = "verify" | "refuse";
|
|
44
|
+
/** One model's classification in the tenancy map. */
|
|
45
|
+
export type ScopedModelEntry = "none" | {
|
|
46
|
+
readonly column: string;
|
|
47
|
+
readonly nested?: ScopedNestedMode;
|
|
48
|
+
} | {
|
|
49
|
+
readonly through: string;
|
|
50
|
+
readonly nested?: ScopedNestedMode;
|
|
51
|
+
};
|
|
52
|
+
/** The per-model tenancy map — must classify EVERY model (totality). */
|
|
53
|
+
export type ScopedModelsMap = Readonly<Record<string, ScopedModelEntry>>;
|
|
54
|
+
/** The `$scoped` argument. */
|
|
55
|
+
export type ScopedClientConfig = {
|
|
56
|
+
readonly scope: ScopeValue | null;
|
|
57
|
+
readonly models: ScopedModelsMap;
|
|
58
|
+
};
|
|
59
|
+
type ResolvedEntry = {
|
|
60
|
+
readonly kind: "none";
|
|
61
|
+
} | {
|
|
62
|
+
readonly kind: "column";
|
|
63
|
+
readonly field: FieldMeta;
|
|
64
|
+
readonly nested: ScopedNestedMode;
|
|
65
|
+
} | {
|
|
66
|
+
readonly kind: "through";
|
|
67
|
+
readonly relation: RelationIR;
|
|
68
|
+
readonly targetModel: string;
|
|
69
|
+
readonly nested: ScopedNestedMode;
|
|
70
|
+
};
|
|
71
|
+
type ResolvedScopedModels = ReadonlyMap<string, ResolvedEntry>;
|
|
72
|
+
/**
|
|
73
|
+
* Validate the models map against the runtime meta: totality, known
|
|
74
|
+
* columns/relations, scopeable column types, acyclic through-chains ending on
|
|
75
|
+
* a { column } model. Cached by (map, meta) object identity — the framework
|
|
76
|
+
* holds one map constant and calls `$scoped` per request.
|
|
77
|
+
*/
|
|
78
|
+
export declare function resolveScopedModels(params: {
|
|
79
|
+
meta: RuntimeMeta;
|
|
80
|
+
models: ScopedModelsMap;
|
|
81
|
+
}): ResolvedScopedModels;
|
|
82
|
+
/** A rewritten call: which base-delegate method to run, with which args. */
|
|
83
|
+
export type RewrittenScopedCall = {
|
|
84
|
+
readonly model: string;
|
|
85
|
+
readonly method: string;
|
|
86
|
+
readonly args: ClientRow | undefined;
|
|
87
|
+
};
|
|
88
|
+
/** A validated, scope-bound rewriter — the pure core a binding's tests drive. */
|
|
89
|
+
export type ScopeRewriter = {
|
|
90
|
+
readonly rewrite: (call: {
|
|
91
|
+
model: string;
|
|
92
|
+
method: string;
|
|
93
|
+
args?: ClientRow;
|
|
94
|
+
}) => RewrittenScopedCall;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Validate a models map + scope against the runtime meta and return the pure
|
|
98
|
+
* per-call rewriter (`ScopedQueryError` on refusals). This is `$scoped`'s
|
|
99
|
+
* engine without the client plumbing — conformance rewrite-vectors run here.
|
|
100
|
+
*/
|
|
101
|
+
export declare function createScopeRewriter(params: {
|
|
102
|
+
meta: RuntimeMeta;
|
|
103
|
+
models: ScopedModelsMap;
|
|
104
|
+
scope: ScopeValue | null;
|
|
105
|
+
}): ScopeRewriter;
|
|
106
|
+
/**
|
|
107
|
+
* Rewrite ONE delegate call for a scoped handle — pure: same inputs, same
|
|
108
|
+
* output; refusals throw `ScopedQueryError` before any SQL could run. This is
|
|
109
|
+
* the function the conformance rewrite-vectors pin.
|
|
110
|
+
*/
|
|
111
|
+
export declare function rewriteScopedCall(params: {
|
|
112
|
+
meta: RuntimeMeta;
|
|
113
|
+
resolved: ResolvedScopedModels;
|
|
114
|
+
scope: ScopeValue | null;
|
|
115
|
+
preds: ReadonlyMap<string, ClientRow | null>;
|
|
116
|
+
model: string;
|
|
117
|
+
method: string;
|
|
118
|
+
args: ClientRow | undefined;
|
|
119
|
+
}): RewrittenScopedCall;
|
|
120
|
+
/**
|
|
121
|
+
* Attach `$scoped` to a built client. Validation happens per call:
|
|
122
|
+
* `@@policy` schemas refuse (the two scoping layers do not combine), the
|
|
123
|
+
* models map is resolved against the schema (cached by object identity), and
|
|
124
|
+
* the scope value is type-checked against every scoped column.
|
|
125
|
+
*/
|
|
126
|
+
export declare function attachScoped(params: {
|
|
127
|
+
client: DynamicClient;
|
|
128
|
+
meta: RuntimeMeta;
|
|
129
|
+
}): void;
|
|
130
|
+
export {};
|
|
131
|
+
//# sourceMappingURL=scoped.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoped.d.ts","sourceRoot":"","sources":["../src/scoped.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAuB,MAAM,iBAAiB,CAAC;AAEvE,OAAO,KAAK,EAAE,SAAS,EAAa,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,KAAK,EAAe,SAAS,EAAE,aAAa,EAAiB,MAAM,aAAa,CAAC;AAKxF,sFAAsF;AACtF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAElD;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEnD,qDAAqD;AACrD,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAA;CAAE,GAC/D;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAErE,wEAAwE;AACxE,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAEzE,8BAA8B;AAC9B,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CA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AE,WAAW,CAAC;IAClB,MAAM,EAAE,eAAe,CAAC;IACxB,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CAC1B,GAAG,aAAa,CAkBhB;AAID;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IACxC,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IACzB,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC,CAAC;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;CAC7B,GAAG,mBAAmB,CA0GtB;AAiKD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GAAG,IAAI,CAuCvF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in write-boundary validation (EPIC 3) — Standard-Schema validators
|
|
3
|
+
* mounted per model × field, run on every write path (nested creates
|
|
4
|
+
* included) BEFORE the data reaches the encoder. Decode-side is deliberately
|
|
5
|
+
* untouched: validation taxes writes the caller opted into, never every row
|
|
6
|
+
* materialization (rule 8; board #30).
|
|
7
|
+
*
|
|
8
|
+
* The interface is the published Standard Schema contract
|
|
9
|
+
* (https://standardschema.dev) — zod, valibot and arktype all implement it —
|
|
10
|
+
* vendored as a minimal type so the runtime takes no dependency.
|
|
11
|
+
*/
|
|
12
|
+
import type { ModelMeta, RuntimeMeta } from "./model-meta.ts";
|
|
13
|
+
/** One validation issue as Standard Schema defines it. */
|
|
14
|
+
export type StandardIssue = {
|
|
15
|
+
readonly message: string;
|
|
16
|
+
readonly path?: ReadonlyArray<PropertyKey | {
|
|
17
|
+
readonly key: PropertyKey;
|
|
18
|
+
}>;
|
|
19
|
+
};
|
|
20
|
+
/** The Standard Schema v1 contract — the only surface the runtime touches. */
|
|
21
|
+
export type StandardSchemaV1<Input = unknown, Output = Input> = {
|
|
22
|
+
readonly "~standard": {
|
|
23
|
+
readonly version: 1;
|
|
24
|
+
readonly vendor: string;
|
|
25
|
+
readonly validate: (value: unknown) => {
|
|
26
|
+
value: Output;
|
|
27
|
+
issues?: undefined;
|
|
28
|
+
} | {
|
|
29
|
+
issues: readonly StandardIssue[];
|
|
30
|
+
} | Promise<unknown>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/** Per-model, per-field validator config: `{ User: { settings: zodSchema } }`. */
|
|
34
|
+
export type WriteValidators = {
|
|
35
|
+
readonly [model: string]: {
|
|
36
|
+
readonly [field: string]: StandardSchemaV1;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Validate one data row (create/update shape) for `model`, recursing into
|
|
41
|
+
* nested `create`/`createMany`/`connectOrCreate.create`/`upsert.create` and
|
|
42
|
+
* nested `update` bodies on related models that carry validators. Returns the
|
|
43
|
+
* (possibly transformed) data — Standard Schema allows coercion.
|
|
44
|
+
*/
|
|
45
|
+
export declare function validateWriteData(params: {
|
|
46
|
+
meta: RuntimeMeta;
|
|
47
|
+
model: ModelMeta;
|
|
48
|
+
data: Record<string, unknown>;
|
|
49
|
+
validators: WriteValidators;
|
|
50
|
+
}): Record<string, unknown>;
|
|
51
|
+
/** Rewrite a write method's args through the validators; non-write args pass through untouched. */
|
|
52
|
+
export declare function applyWriteValidators(params: {
|
|
53
|
+
meta: RuntimeMeta;
|
|
54
|
+
model: ModelMeta;
|
|
55
|
+
method: string;
|
|
56
|
+
args: Record<string, unknown>;
|
|
57
|
+
validators: WriteValidators;
|
|
58
|
+
}): Record<string, unknown>;
|
|
59
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources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,CAAC,CAuD1B;AAED,mGAAmG;AACnG,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAC3C,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,UAAU,EAAE,eAAe,CAAC;CAC7B,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiB1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibeorm/runtime",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.9",
|
|
4
4
|
"description": "Driver-agnostic query engine and client runtime for VibeORM v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"orm",
|
|
@@ -41,11 +41,12 @@
|
|
|
41
41
|
"bun": ">=1.2.0"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@vibeorm/schema": "2.0.0-alpha.
|
|
45
|
-
"@vibeorm/sql": "2.0.0-alpha.
|
|
44
|
+
"@vibeorm/schema": "2.0.0-alpha.7",
|
|
45
|
+
"@vibeorm/sql": "2.0.0-alpha.7"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@electric-sql/pglite": "^0.5.4"
|
|
48
|
+
"@electric-sql/pglite": "^0.5.4",
|
|
49
|
+
"@vibeorm/scoped-conformance": "0.1.0-alpha.0"
|
|
49
50
|
},
|
|
50
51
|
"publishConfig": {
|
|
51
52
|
"access": "public"
|