@drhomet/mithaq 0.0.0-stage → 0.2.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.
Files changed (152) hide show
  1. package/LICENSE +22 -0
  2. package/LICENSES/openstatus-time-picker.txt +21 -0
  3. package/LICENSES/payload.txt +22 -0
  4. package/LICENSES/ponytail.txt +21 -0
  5. package/README.md +160 -2
  6. package/dist/asas/actor.d.ts +96 -0
  7. package/dist/asas/actor.js +114 -0
  8. package/dist/asas/build.d.ts +239 -0
  9. package/dist/asas/build.js +834 -0
  10. package/dist/asas/cli/mithaq.d.ts +2 -0
  11. package/dist/asas/cli/mithaq.js +177 -0
  12. package/dist/asas/cli/upgrade.d.ts +33 -0
  13. package/dist/asas/cli/upgrade.js +256 -0
  14. package/dist/asas/http/fetch.d.ts +41 -0
  15. package/dist/asas/http/fetch.js +178 -0
  16. package/dist/asas/http/orpc.d.ts +45 -0
  17. package/dist/asas/http/orpc.js +153 -0
  18. package/dist/asas/runner/bulk.d.ts +20 -0
  19. package/dist/asas/runner/bulk.js +196 -0
  20. package/dist/asas/runner/errors.d.ts +63 -0
  21. package/dist/asas/runner/errors.js +75 -0
  22. package/dist/asas/runner/read.d.ts +72 -0
  23. package/dist/asas/runner/read.js +601 -0
  24. package/dist/asas/runner/runtime.d.ts +21 -0
  25. package/dist/asas/runner/runtime.js +8 -0
  26. package/dist/asas/runner/steps.d.ts +418 -0
  27. package/dist/asas/runner/steps.js +277 -0
  28. package/dist/asas/runner/store.d.ts +4 -0
  29. package/dist/asas/runner/store.js +21 -0
  30. package/dist/asas/runner/tenant.d.ts +54 -0
  31. package/dist/asas/runner/tenant.js +275 -0
  32. package/dist/asas/runner/write.d.ts +606 -0
  33. package/dist/asas/runner/write.js +1019 -0
  34. package/dist/auth/better-auth/access.d.ts +29 -0
  35. package/dist/auth/better-auth/access.js +103 -0
  36. package/dist/auth/better-auth/generate.d.ts +31 -0
  37. package/dist/auth/better-auth/generate.js +328 -0
  38. package/dist/auth/better-auth/index.d.ts +94 -0
  39. package/dist/auth/better-auth/index.js +81 -0
  40. package/dist/auth/better-auth/tenant.d.ts +26 -0
  41. package/dist/auth/better-auth/tenant.js +34 -0
  42. package/dist/auth/local/index.d.ts +285 -0
  43. package/dist/auth/local/index.js +738 -0
  44. package/dist/base/decimal.d.ts +9 -0
  45. package/dist/base/decimal.js +16 -0
  46. package/dist/base/fields.d.ts +124 -0
  47. package/dist/base/fields.js +52 -0
  48. package/dist/base/index.d.ts +47 -0
  49. package/dist/base/index.js +5 -0
  50. package/dist/base/json-schema.d.ts +7 -0
  51. package/dist/base/json-schema.js +35 -0
  52. package/dist/base/kinds.d.ts +75 -0
  53. package/dist/base/kinds.js +123 -0
  54. package/dist/base/rules.d.ts +73 -0
  55. package/dist/base/rules.js +81 -0
  56. package/dist/drizzle/index.d.ts +308 -0
  57. package/dist/drizzle/index.js +951 -0
  58. package/dist/drizzle/kinds.d.ts +28 -0
  59. package/dist/drizzle/kinds.js +43 -0
  60. package/dist/drizzle/migrate.d.ts +159 -0
  61. package/dist/drizzle/migrate.js +1328 -0
  62. package/dist/drizzle/proxy/index.d.ts +1 -0
  63. package/dist/drizzle/proxy/index.js +1 -0
  64. package/dist/drizzle/proxy/node-postgres.d.ts +1 -0
  65. package/dist/drizzle/proxy/node-postgres.js +1 -0
  66. package/dist/drizzle/proxy/pg-core.d.ts +1 -0
  67. package/dist/drizzle/proxy/pg-core.js +1 -0
  68. package/dist/drizzle/rules.d.ts +336 -0
  69. package/dist/drizzle/rules.js +44 -0
  70. package/dist/index.d.ts +35 -0
  71. package/dist/index.js +26 -0
  72. package/dist/mithaq/define.d.ts +335 -0
  73. package/dist/mithaq/define.js +57 -0
  74. package/dist/mithaq/generate-messages.d.ts +38 -0
  75. package/dist/mithaq/generate-messages.js +235 -0
  76. package/dist/mithaq/language.d.ts +374 -0
  77. package/dist/mithaq/language.js +76 -0
  78. package/dist/mithaq/lock.d.ts +71 -0
  79. package/dist/mithaq/lock.js +329 -0
  80. package/dist/mithaq/message-file.d.ts +13 -0
  81. package/dist/mithaq/message-file.js +29 -0
  82. package/dist/mithaq/messages.d.ts +55 -0
  83. package/dist/mithaq/messages.js +111 -0
  84. package/dist/mithaq/refusal.d.ts +6 -0
  85. package/dist/mithaq/refusal.js +6 -0
  86. package/dist/mithaq/resolve.d.ts +10 -0
  87. package/dist/mithaq/resolve.js +1014 -0
  88. package/dist/mithaq/rows.d.ts +87 -0
  89. package/dist/mithaq/rows.js +174 -0
  90. package/dist/mithaq/rukn.d.ts +72 -0
  91. package/dist/mithaq/rukn.js +15 -0
  92. package/dist/mithaq/standard-schema.d.ts +38 -0
  93. package/dist/mithaq/standard-schema.js +2 -0
  94. package/dist/mithaq/types.d.ts +386 -0
  95. package/dist/mithaq/types.js +15 -0
  96. package/dist/mithaq/user.d.ts +19 -0
  97. package/dist/mithaq/user.js +16 -0
  98. package/dist/mithaq/where.d.ts +32 -0
  99. package/dist/mithaq/where.js +87 -0
  100. package/dist/rbac/index.d.ts +105 -0
  101. package/dist/rbac/index.js +182 -0
  102. package/dist/rbac/steps.d.ts +22 -0
  103. package/dist/rbac/steps.js +161 -0
  104. package/dist/rich-text/index.d.ts +28 -0
  105. package/dist/rich-text/index.js +59 -0
  106. package/dist/rich-text/rich-text.d.ts +106 -0
  107. package/dist/rich-text/rich-text.js +249 -0
  108. package/dist/rich-text/value.d.ts +55 -0
  109. package/dist/rich-text/value.js +126 -0
  110. package/dist/screen/client.d.ts +156 -0
  111. package/dist/screen/client.js +71 -0
  112. package/dist/screen/generate.d.ts +14 -0
  113. package/dist/screen/generate.js +268 -0
  114. package/dist/screen/index.d.ts +496 -0
  115. package/dist/screen/index.js +663 -0
  116. package/dist/screen/react.d.ts +97 -0
  117. package/dist/screen/react.js +58 -0
  118. package/dist/screen/studio.d.ts +24 -0
  119. package/dist/screen/studio.js +68 -0
  120. package/dist/service/index.d.ts +63 -0
  121. package/dist/service/index.js +15 -0
  122. package/dist/storage/allowed-type.d.ts +5 -0
  123. package/dist/storage/allowed-type.js +7 -0
  124. package/dist/storage/index.d.ts +42 -0
  125. package/dist/storage/index.js +43 -0
  126. package/dist/storage/storage.d.ts +386 -0
  127. package/dist/storage/storage.js +412 -0
  128. package/dist/targets.d.ts +14 -0
  129. package/dist/targets.js +16 -0
  130. package/dist/versions/index.d.ts +37 -0
  131. package/dist/versions/index.js +8 -0
  132. package/dist/versions/versions.d.ts +104 -0
  133. package/dist/versions/versions.js +160 -0
  134. package/dist/vite.d.ts +7 -0
  135. package/dist/vite.js +81 -0
  136. package/dist/zod/index.d.ts +193 -0
  137. package/dist/zod/index.js +122 -0
  138. package/dist/zod/kinds.d.ts +36 -0
  139. package/dist/zod/kinds.js +58 -0
  140. package/dist/zod/rules.d.ts +117 -0
  141. package/dist/zod/rules.js +67 -0
  142. package/docs/packages/mithaq/README.md +962 -0
  143. package/docs/packages/mithaq/src/asas/cli/README.md +252 -0
  144. package/docs/packages/mithaq/src/asas/runner/README.md +472 -0
  145. package/docs/packages/mithaq/src/drizzle/README.md +39 -0
  146. package/docs/packages/mithaq-admin/README.md +312 -0
  147. package/docs/templates/asas/README.md +1056 -0
  148. package/package.json +92 -4
  149. package/skills/add-field/SKILL.md +27 -0
  150. package/skills/add-kayan/SKILL.md +26 -0
  151. package/skills/eject-admin-piece/SKILL.md +28 -0
  152. package/skills/upgrade-mithaq/SKILL.md +35 -0
@@ -0,0 +1,81 @@
1
+ import { isRef } from '../mithaq/user.js';
2
+ import { isJson } from './kinds.js';
3
+ /** Defines a project rule from its runtime check. */
4
+ export const rule = ({ accepts, message, excludes, }) => ({ value: undefined, accepts, message, excludes });
5
+ const isBoolean = (value) => typeof value === 'boolean';
6
+ const isNumber = (value) => typeof value === 'number';
7
+ const boolean = rule({ accepts: isBoolean });
8
+ const writeOperations = ['create', 'update'];
9
+ // `never` is not `application`: not "something else fills it" but "nobody does, for this operation".
10
+ const providers = ['client', 'application', 'never'];
11
+ /** Who supplies a field's value on one operation; a field that declares nothing is the client's. */
12
+ export const providerOf = (field, on) => field.rules?.providedBy?.[on] ?? 'client';
13
+ /** The shipped rules, which a project passes to `defineMithaq` and may add its own to. */
14
+ export const defaultRules = {
15
+ required: rule({ accepts: isBoolean, message: { en: 'This field is required.', ar: 'هذا الحقل مطلوب.' } }),
16
+ unique: boolean,
17
+ index: boolean,
18
+ /** A literal, JSON for a `json` field, or `user.<key>` for the actor's value. Each row gets its own copy. */
19
+ defaultValue: rule({
20
+ accepts: (value) => value instanceof Date || isRef(value) || Array.isArray(value) || (value !== null && isJson(value)),
21
+ excludes: ['defaultNow'],
22
+ }),
23
+ /** The moment of the write, on create. */
24
+ defaultNow: rule({ accepts: isBoolean, excludes: ['defaultValue', 'localized'] }),
25
+ /** The moment of the write, on every update, whatever the column is called. */
26
+ nowOnUpdate: rule({ accepts: isBoolean, excludes: ['localized'] }),
27
+ /** Who supplies the value on create and on update. A field declaring nothing is the client's on both. */
28
+ providedBy: rule({
29
+ accepts: (value) => !!value &&
30
+ typeof value === 'object' &&
31
+ !Array.isArray(value) &&
32
+ Object.entries(value).every(([operation, supplier]) => writeOperations.includes(operation) && providers.includes(supplier)),
33
+ }),
34
+ /** One value per locale the language declares: one column per locale, and an object keyed by locale in every shape. */
35
+ localized: boolean,
36
+ /** Length is a rule, not a kind: `text` with a maximum is `varchar(n)`. */
37
+ maxLength: rule({ accepts: isNumber, message: { en: 'The value is too long.', ar: 'القيمة طويلة جدًا.' } }),
38
+ /** A decimal's size, `numeric(precision, scale)`: declare both or neither. A value with more digits is refused, not rounded. */
39
+ precision: rule({
40
+ accepts: (value) => Number.isInteger(value) && value >= 1 && value <= 1000,
41
+ message: { en: 'The value has too many digits.', ar: 'القيمة فيها أرقام أكثر من المسموح.' },
42
+ }),
43
+ scale: rule({
44
+ accepts: (value) => Number.isInteger(value) && value >= 0 && value <= 1000,
45
+ message: { en: 'The value has too many decimal places.', ar: 'القيمة فيها منازل عشرية أكثر من المسموح.' },
46
+ }),
47
+ minLength: rule({ accepts: isNumber, message: { en: 'The value is too short.', ar: 'القيمة أقصر من المسموح.' } }),
48
+ pattern: rule({
49
+ accepts: (value) => value instanceof RegExp,
50
+ message: {
51
+ en: 'The value is not in the shape this field takes.',
52
+ ar: 'القيمة ليست بالشكل الذي يقبله هذا الحقل.',
53
+ },
54
+ }),
55
+ /** A bound on an ordered value: a number for `number`, an ISO day for `date`. */
56
+ min: rule({
57
+ accepts: (value) => typeof value === 'number' || typeof value === 'string',
58
+ message: { en: 'The value is too small.', ar: 'القيمة أصغر من المسموح.' },
59
+ }),
60
+ max: rule({
61
+ accepts: (value) => typeof value === 'number' || typeof value === 'string',
62
+ message: { en: 'The value is too large.', ar: 'القيمة أكبر من المسموح.' },
63
+ }),
64
+ /** How few and how many rows a list holds. A list that is not `required` may be left empty whatever its floor. */
65
+ minRows: rule({
66
+ accepts: (value) => Number.isInteger(value) && value >= 0,
67
+ message: { en: 'This list has too few entries.', ar: 'هذه القائمة فيها عناصر أقل من المسموح.' },
68
+ }),
69
+ maxRows: rule({
70
+ accepts: (value) => Number.isInteger(value) && value >= 0,
71
+ message: { en: 'This list has too many entries.', ar: 'هذه القائمة فيها عناصر أكثر من المسموح.' },
72
+ }),
73
+ /** Rewrites the value's case before any check judges it; never refuses a value for its case. */
74
+ uppercase: rule({ accepts: isBoolean, excludes: ['lowercase'] }),
75
+ lowercase: rule({ accepts: isBoolean, excludes: ['uppercase'] }),
76
+ trim: boolean,
77
+ /** What happens to this row when the row it points at is deleted. Left out, a required field and a set restrict and any other takes its kind's default. */
78
+ onDelete: rule({
79
+ accepts: (value) => typeof value === 'string' && ['cascade', 'restrict', 'set null'].includes(value),
80
+ }),
81
+ };
@@ -0,0 +1,308 @@
1
+ import { type SQL } from 'drizzle-orm';
2
+ import { type NodePgDatabase } from 'drizzle-orm/node-postgres';
3
+ import { pgTable, type AnyPgColumnBuilder, type PgBooleanBuilder, type PgBuildColumns, type PgEnum, type PgDateStringBuilder, type PgIntegerBuilder, type PgJsonbBuilder, type PgNumericBuilder, type PgNumericNumberBuilder, type PgSchema, type PgSerialBuilder, type PgTable, type PgTableWithColumns, type PgTextBuilder, type PgTimestampBuilder, type PgUUIDBuilder, type PgVarcharBuilder, type SetDimensions, type SetHasDefault, type SetNotNull } from 'drizzle-orm/pg-core';
4
+ import type { ResolvedField, ResolvedKayan, RuntimeField } from '../mithaq/types.ts';
5
+ import type { Store } from '../mithaq/language.ts';
6
+ import type { Operator } from '../mithaq/where.ts';
7
+ type Database = NodePgDatabase;
8
+ export type Tables = Record<string, ReturnType<typeof pgTable>>;
9
+ export type Schemas = Record<string, PgSchema | null>;
10
+ /** Every enum a built column uses, keyed `<schema>.<name>`. */
11
+ export type Enums = Record<string, PgEnum<[string, ...string[]]>>;
12
+ type Registry = readonly {
13
+ name: string;
14
+ fields: Record<string, RuntimeField>;
15
+ }[];
16
+ type Related<F, List extends Registry> = F extends {
17
+ relationTo: infer Relation;
18
+ } ? Relation extends string ? Extract<List[number], {
19
+ name: Relation;
20
+ }> : Relation extends () => {
21
+ name: infer Name;
22
+ } ? Extract<List[number], {
23
+ name: Name;
24
+ }> : never : never;
25
+ type OwnBuilder<F, Kinds> = F extends {
26
+ kind: infer Kind extends keyof Kinds;
27
+ } ? Kinds[Kind] extends {
28
+ readonly targets: {
29
+ readonly drizzle: (...args: never[]) => infer Own extends AnyPgColumnBuilder;
30
+ };
31
+ } ? Own : never : never;
32
+ type BaseBuilder<F, List extends Registry, Name, Store extends PropertyKey, Kinds> = F extends {
33
+ targets: Record<Store, infer Override extends AnyPgColumnBuilder>;
34
+ } ? Override : F extends {
35
+ relationTo: unknown;
36
+ } ? ReferenceBuilder<F, List> : [OwnBuilder<F, Kinds>] extends [never] ? ShippedBuilder<F, List, Name> : OwnBuilder<F, Kinds>;
37
+ /** A foreign key takes the type of the id it points at. */
38
+ type ReferenceBuilder<F, List extends Registry> = Related<F, List> extends {
39
+ fields: {
40
+ id: {
41
+ kind: 'number';
42
+ };
43
+ };
44
+ } ? PgIntegerBuilder : Related<F, List> extends {
45
+ fields: {
46
+ id: {
47
+ kind: 'uuid';
48
+ };
49
+ };
50
+ } ? PgUUIDBuilder : PgTextBuilder;
51
+ type ShippedBuilder<F, List extends Registry, Name> = F extends {
52
+ kind: 'number';
53
+ } ? Name extends 'id' ? PgSerialBuilder : PgNumericNumberBuilder : F extends {
54
+ kind: 'integer';
55
+ } ? PgIntegerBuilder : F extends {
56
+ kind: 'decimal';
57
+ } ? PgNumericBuilder : F extends {
58
+ kind: 'uuid';
59
+ } ? PgUUIDBuilder : F extends {
60
+ kind: 'checkbox';
61
+ } ? PgBooleanBuilder : F extends {
62
+ kind: 'textArray';
63
+ } ? SetDimensions<PgTextBuilder, 1> : F extends {
64
+ kind: 'datetime';
65
+ } ? PgTimestampBuilder : F extends {
66
+ kind: 'date';
67
+ } ? PgDateStringBuilder : F extends {
68
+ kind: 'json';
69
+ } ? PgJsonbBuilder : F extends {
70
+ rules: {
71
+ maxLength: number;
72
+ };
73
+ } ? PgVarcharBuilder : PgTextBuilder;
74
+ type DefaultedBuilder<B extends AnyPgColumnBuilder, F, Name> = Name extends 'id' ? SetHasDefault<B> : F extends {
75
+ rules: {
76
+ defaultValue: unknown;
77
+ };
78
+ } | {
79
+ rules: {
80
+ defaultNow: true;
81
+ };
82
+ } ? SetHasDefault<B> : B;
83
+ type PreparedBuilder<B extends AnyPgColumnBuilder, F, Name> = B extends AnyPgColumnBuilder ? F extends {
84
+ rules: {
85
+ required: true;
86
+ };
87
+ } ? SetNotNull<DefaultedBuilder<B, F, Name>> : DefaultedBuilder<B, F, Name> : never;
88
+ type NameOf<K> = K extends {
89
+ name: infer Name extends string;
90
+ } ? Name : string;
91
+ type TableName<K> = K extends {
92
+ dbName?: infer Name extends string;
93
+ } ? string extends Name ? NameOf<K> : Name : NameOf<K>;
94
+ type Builders<K, List extends Registry, Store extends PropertyKey, Kinds> = K extends {
95
+ fields: infer Fields extends Record<string, RuntimeField>;
96
+ } ? {
97
+ [Name in keyof Fields as Fields[Name] extends {
98
+ hasMany: true;
99
+ } | {
100
+ kind: 'join';
101
+ } ? never : Name]: PreparedBuilder<BaseBuilder<Fields[Name], List, Name, Store, Kinds>, Fields[Name], Name>;
102
+ } : never;
103
+ type SnakeRest<S extends string> = S extends `${infer Head}${infer Rest}` ? Lowercase<Head> extends Head ? `${Head}${SnakeRest<Rest>}` : `_${Lowercase<Head>}${SnakeRest<Rest>}` : '';
104
+ type SnakeCase<S extends string> = S extends `${infer Head}${infer Rest}` ? `${Lowercase<Head>}${SnakeRest<Rest>}` : S;
105
+ /** The join table names one kayan's `hasMany` fields ask for, as `joinTableOf` builds them. */
106
+ type JoinNames<K> = K extends {
107
+ fields: infer Fields;
108
+ } ? {
109
+ [Name in keyof Fields]: Fields[Name] extends {
110
+ hasMany: true;
111
+ } ? `${TableName<K>}_${SnakeCase<Name & string>}` : never;
112
+ }[keyof Fields] : never;
113
+ type VersionsName<K> = `_${TableName<K>}_versions`;
114
+ type StoreKayan<K, StoreName extends PropertyKey, DefaultStore extends PropertyKey> = K extends {
115
+ targets: {
116
+ service: {
117
+ store: infer Named;
118
+ };
119
+ };
120
+ } ? Named extends StoreName ? K : never : DefaultStore extends StoreName ? K : never;
121
+ type TableFor<K, List extends Registry, Store extends PropertyKey, Kinds> = K extends {
122
+ targets: Record<Store, infer Override>;
123
+ } ? Override : PgTableWithColumns<{
124
+ name: TableName<K>;
125
+ schema: undefined;
126
+ columns: PgBuildColumns<TableName<K>, Builders<K, List, Store, Kinds>>;
127
+ dialect: 'pg';
128
+ }>;
129
+ /** Concrete tables built for one store, keyed by registered kayan names. */
130
+ export type BuiltTables<List extends Registry, StoreName extends PropertyKey, DefaultStore extends PropertyKey, Kinds = {}> = {
131
+ [K in StoreKayan<List[number], StoreName, DefaultStore> as K['name']]: TableFor<K, List, StoreName, Kinds>;
132
+ } & {
133
+ [K in StoreKayan<List[number], StoreName, DefaultStore> as JoinNames<K>]: ReturnType<typeof pgTable>;
134
+ } & {
135
+ [K in StoreKayan<List[number], StoreName, DefaultStore> as VersionsName<K>]?: ReturnType<typeof pgTable>;
136
+ };
137
+ /** Builds one field's column. `tables` is every table built so far, keyed by kayan name, which a foreign key reads lazily. */
138
+ export type ColumnBuilder = (field: ResolvedField, tables: Tables) => AnyPgColumnBuilder;
139
+ type Modifiable = AnyPgColumnBuilder & {
140
+ default(value: unknown): Modifiable;
141
+ notNull(): Modifiable;
142
+ primaryKey(): Modifiable;
143
+ unique(): Modifiable;
144
+ };
145
+ export declare const joinTableOf: (kayan: ResolvedKayan, field: ResolvedField) => string;
146
+ /** The fields of one kayan the store holds as a join table rather than a column. */
147
+ export declare const manyFields: (kayan: ResolvedKayan | undefined) => ({
148
+ access?: {
149
+ create?: import("../mithaq/types.ts").FieldAccess<unknown, Record<string, unknown>, unknown, Partial<Record<string, unknown>>> | (import("../mithaq/types.ts").ActorBoundAccess<unknown> & {
150
+ readonly __mithaqFieldData: unknown;
151
+ readonly __mithaqFieldId: unknown;
152
+ });
153
+ read?: import("../mithaq/types.ts").FieldAccess<unknown, Record<string, unknown>, unknown, Partial<Record<string, unknown>>> | (import("../mithaq/types.ts").ActorBoundAccess<unknown> & {
154
+ readonly __mithaqFieldData: unknown;
155
+ readonly __mithaqFieldId: unknown;
156
+ });
157
+ update?: import("../mithaq/types.ts").FieldAccess<unknown, Record<string, unknown>, unknown, Partial<Record<string, unknown>>> | (import("../mithaq/types.ts").ActorBoundAccess<unknown> & {
158
+ readonly __mithaqFieldData: unknown;
159
+ readonly __mithaqFieldId: unknown;
160
+ });
161
+ };
162
+ label?: import("../mithaq/types.ts").LabelFunction | Readonly<Record<string, string>> | undefined;
163
+ description?: import("../mithaq/types.ts").LabelFunction | Readonly<Record<string, string>> | undefined;
164
+ placeholder?: import("../mithaq/types.ts").LabelFunction | Readonly<Record<string, string>> | undefined;
165
+ prefix?: Readonly<Record<string, string>> | undefined;
166
+ suffix?: Readonly<Record<string, string>> | undefined;
167
+ options?: readonly {
168
+ readonly value: string;
169
+ readonly label: Readonly<Record<string, string>>;
170
+ }[] | undefined;
171
+ jsonSchema?: import("../mithaq/types.ts").JsonSchema;
172
+ maxBytes?: number;
173
+ dbName?: string;
174
+ targets?: Record<string, unknown>;
175
+ custom?: Record<string, unknown>;
176
+ } & {
177
+ kind: string;
178
+ rules?: Record<string, unknown>;
179
+ relationTo?: string | (() => import("../mithaq/types.ts").Kayan);
180
+ hasMany?: true;
181
+ filterOptions?: import("../mithaq/types.ts").FilterOptions;
182
+ on?: string;
183
+ defaultLimit?: number;
184
+ defaultSort?: string;
185
+ } & {
186
+ name: string;
187
+ column: string;
188
+ kayan?: string;
189
+ schemaTarget?: string;
190
+ locales?: readonly string[];
191
+ now?: () => unknown;
192
+ kindTargets?: Readonly<Record<string, unknown>>;
193
+ operators?: readonly Operator[];
194
+ sortable?: false;
195
+ filesIn?: readonly string[];
196
+ richText?: (value: unknown) => import("../rich-text/value.ts").RichTextRead;
197
+ target?: ResolvedKayan;
198
+ })[];
199
+ export declare const schemaOf: (table: unknown) => string;
200
+ export type ColumnRule<Value = never> = (args: {
201
+ column: Modifiable;
202
+ value: Value;
203
+ field: ResolvedField;
204
+ }) => Modifiable;
205
+ /** The drizzle store: a store, plus the drizzle instance and the tables it built, read off `asas.targets.drizzle`. */
206
+ export type Adapter = Omit<Store, 'kinds' | 'rules'> & {
207
+ kinds: Record<string, ColumnBuilder>;
208
+ rules: Record<string, ColumnRule>;
209
+ readonly type: 'drizzle';
210
+ /** Declared, never sniffed: what says the two members below are drizzle's. */
211
+ readonly sql: 'drizzle';
212
+ db: Database;
213
+ tables: Tables;
214
+ /** Every schema the built tables are in. The push hands them to drizzle-kit, which writes no `CREATE SCHEMA` otherwise. */
215
+ schemas: Schemas;
216
+ /** Every enum a built column uses, keyed `<schema>.<name>`. drizzle-kit writes no `CREATE TYPE` for one it is not handed. */
217
+ enums: Enums;
218
+ /** The string this adapter made its instance from, which `mithaq migrate` writes into the drizzle-kit config. */
219
+ readonly connectionString?: string;
220
+ };
221
+ export declare const devPushMarker = "mithaq_dev_push";
222
+ export declare const migrationsTable: {
223
+ readonly schema: 'drizzle';
224
+ readonly table: '__mithaq_migrations';
225
+ };
226
+ export declare const refuseStrangers: ({ db, tables, by }: {
227
+ db: {
228
+ execute(query: SQL): Promise<{
229
+ rows: unknown[];
230
+ }>;
231
+ };
232
+ tables: Tables;
233
+ /** What would drop the stranger, which the sentence names. */
234
+ by: 'push' | 'baseline';
235
+ }) => Promise<void>;
236
+ export declare const pushInput: ({ tables, schemas, held }: {
237
+ tables: Tables;
238
+ schemas: Schemas;
239
+ held?: {
240
+ schema: string;
241
+ name: string;
242
+ labels: string[];
243
+ owned: boolean;
244
+ }[];
245
+ }) => {
246
+ imports: Record<string, unknown>;
247
+ filter: {
248
+ schemas: string[];
249
+ tables: any[];
250
+ entities: undefined;
251
+ extensions: never[];
252
+ };
253
+ };
254
+ /** The history table as SQL, for the statements that read and write it. */
255
+ export declare const historyTable: SQL<unknown>;
256
+ /**
257
+ * The one lock every writer of the history takes, a production boot running drizzle's migrator
258
+ * and a connect making the table, since both create the `drizzle` schema. Keyed as a boot has
259
+ * always keyed it, so an instance of an older release booting beside this one still waits.
260
+ */
261
+ export declare const historyLock: SQL<unknown>;
262
+ type HistoryDb = {
263
+ execute(query: SQL): Promise<unknown>;
264
+ transaction<T>(run: (tx: {
265
+ execute(query: SQL): Promise<unknown>;
266
+ }) => Promise<T>): Promise<T>;
267
+ };
268
+ export declare const createHistory: (db: HistoryDb) => Promise<void>;
269
+ export declare const recordMigration: ({ db, hash, createdAt, name }: {
270
+ db: HistoryDb;
271
+ hash: string;
272
+ createdAt: number;
273
+ name: string;
274
+ }) => Promise<void>;
275
+ type DrizzleAdapterArguments<Kinds, Rules> = {
276
+ /** A ready drizzle instance, so the pool, logger and options are the developer's. */
277
+ db?: Database;
278
+ /** Or a connection string, and the adapter makes the instance. */
279
+ connectionString?: string;
280
+ kinds: Kinds;
281
+ rules: Rules;
282
+ /** The kinds this store builds an id of; `drizzleIdKinds`, unless you replace the kinds map and its relationship builder. */
283
+ idKinds: readonly string[];
284
+ /** Push the schema on connect instead of running migrations. */
285
+ push?: boolean;
286
+ /**
287
+ * What a production `connect()` does with migrations this database has not applied: `run` applies them
288
+ * in one transaction before serving, `refuse` refuses to start. Without it a production connect refuses.
289
+ */
290
+ prodMigrations?: ProdMigrations;
291
+ };
292
+ /** Where a production connect finds the migrations folder, and what it does with pending ones. */
293
+ export type ProdMigrations = {
294
+ /** The folder of migration folders, as drizzle's own migrator takes it: relative to the working directory, or absolute. */
295
+ migrationsFolder: string;
296
+ pending: 'run' | 'refuse';
297
+ };
298
+ export declare const drizzleAdapter: <const Kinds extends Record<string, ColumnBuilder>, const Rules extends Record<string, ColumnRule>>({ db: ready, connectionString, kinds, rules, idKinds, push: named, prodMigrations, }: DrizzleAdapterArguments<Kinds, Rules>) => Omit<Adapter, 'kinds' | 'rules'> & {
299
+ kinds: Kinds;
300
+ rules: Rules;
301
+ };
302
+ declare module '../mithaq/rukn.ts' {
303
+ /** A kayan's entry under its drizzle store is its whole table, unbuilt, used as written. */
304
+ interface KayanConfigs<L, F, T> {
305
+ drizzle: PgTable;
306
+ }
307
+ }
308
+ export {};