@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.
- package/LICENSE +22 -0
- package/LICENSES/openstatus-time-picker.txt +21 -0
- package/LICENSES/payload.txt +22 -0
- package/LICENSES/ponytail.txt +21 -0
- package/README.md +160 -2
- package/dist/asas/actor.d.ts +96 -0
- package/dist/asas/actor.js +114 -0
- package/dist/asas/build.d.ts +239 -0
- package/dist/asas/build.js +834 -0
- package/dist/asas/cli/mithaq.d.ts +2 -0
- package/dist/asas/cli/mithaq.js +177 -0
- package/dist/asas/cli/upgrade.d.ts +33 -0
- package/dist/asas/cli/upgrade.js +256 -0
- package/dist/asas/http/fetch.d.ts +41 -0
- package/dist/asas/http/fetch.js +178 -0
- package/dist/asas/http/orpc.d.ts +45 -0
- package/dist/asas/http/orpc.js +153 -0
- package/dist/asas/runner/bulk.d.ts +20 -0
- package/dist/asas/runner/bulk.js +196 -0
- package/dist/asas/runner/errors.d.ts +63 -0
- package/dist/asas/runner/errors.js +75 -0
- package/dist/asas/runner/read.d.ts +72 -0
- package/dist/asas/runner/read.js +601 -0
- package/dist/asas/runner/runtime.d.ts +21 -0
- package/dist/asas/runner/runtime.js +8 -0
- package/dist/asas/runner/steps.d.ts +418 -0
- package/dist/asas/runner/steps.js +277 -0
- package/dist/asas/runner/store.d.ts +4 -0
- package/dist/asas/runner/store.js +21 -0
- package/dist/asas/runner/tenant.d.ts +54 -0
- package/dist/asas/runner/tenant.js +275 -0
- package/dist/asas/runner/write.d.ts +606 -0
- package/dist/asas/runner/write.js +1019 -0
- package/dist/auth/better-auth/access.d.ts +29 -0
- package/dist/auth/better-auth/access.js +103 -0
- package/dist/auth/better-auth/generate.d.ts +31 -0
- package/dist/auth/better-auth/generate.js +328 -0
- package/dist/auth/better-auth/index.d.ts +94 -0
- package/dist/auth/better-auth/index.js +81 -0
- package/dist/auth/better-auth/tenant.d.ts +26 -0
- package/dist/auth/better-auth/tenant.js +34 -0
- package/dist/auth/local/index.d.ts +285 -0
- package/dist/auth/local/index.js +738 -0
- package/dist/base/decimal.d.ts +9 -0
- package/dist/base/decimal.js +16 -0
- package/dist/base/fields.d.ts +124 -0
- package/dist/base/fields.js +52 -0
- package/dist/base/index.d.ts +47 -0
- package/dist/base/index.js +5 -0
- package/dist/base/json-schema.d.ts +7 -0
- package/dist/base/json-schema.js +35 -0
- package/dist/base/kinds.d.ts +75 -0
- package/dist/base/kinds.js +123 -0
- package/dist/base/rules.d.ts +73 -0
- package/dist/base/rules.js +81 -0
- package/dist/drizzle/index.d.ts +308 -0
- package/dist/drizzle/index.js +951 -0
- package/dist/drizzle/kinds.d.ts +28 -0
- package/dist/drizzle/kinds.js +43 -0
- package/dist/drizzle/migrate.d.ts +159 -0
- package/dist/drizzle/migrate.js +1328 -0
- package/dist/drizzle/proxy/index.d.ts +1 -0
- package/dist/drizzle/proxy/index.js +1 -0
- package/dist/drizzle/proxy/node-postgres.d.ts +1 -0
- package/dist/drizzle/proxy/node-postgres.js +1 -0
- package/dist/drizzle/proxy/pg-core.d.ts +1 -0
- package/dist/drizzle/proxy/pg-core.js +1 -0
- package/dist/drizzle/rules.d.ts +336 -0
- package/dist/drizzle/rules.js +44 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +26 -0
- package/dist/mithaq/define.d.ts +335 -0
- package/dist/mithaq/define.js +57 -0
- package/dist/mithaq/generate-messages.d.ts +38 -0
- package/dist/mithaq/generate-messages.js +235 -0
- package/dist/mithaq/language.d.ts +374 -0
- package/dist/mithaq/language.js +76 -0
- package/dist/mithaq/lock.d.ts +71 -0
- package/dist/mithaq/lock.js +329 -0
- package/dist/mithaq/message-file.d.ts +13 -0
- package/dist/mithaq/message-file.js +29 -0
- package/dist/mithaq/messages.d.ts +55 -0
- package/dist/mithaq/messages.js +111 -0
- package/dist/mithaq/refusal.d.ts +6 -0
- package/dist/mithaq/refusal.js +6 -0
- package/dist/mithaq/resolve.d.ts +10 -0
- package/dist/mithaq/resolve.js +1014 -0
- package/dist/mithaq/rows.d.ts +87 -0
- package/dist/mithaq/rows.js +174 -0
- package/dist/mithaq/rukn.d.ts +72 -0
- package/dist/mithaq/rukn.js +15 -0
- package/dist/mithaq/standard-schema.d.ts +38 -0
- package/dist/mithaq/standard-schema.js +2 -0
- package/dist/mithaq/types.d.ts +386 -0
- package/dist/mithaq/types.js +15 -0
- package/dist/mithaq/user.d.ts +19 -0
- package/dist/mithaq/user.js +16 -0
- package/dist/mithaq/where.d.ts +32 -0
- package/dist/mithaq/where.js +87 -0
- package/dist/rbac/index.d.ts +105 -0
- package/dist/rbac/index.js +182 -0
- package/dist/rbac/steps.d.ts +22 -0
- package/dist/rbac/steps.js +161 -0
- package/dist/rich-text/index.d.ts +28 -0
- package/dist/rich-text/index.js +59 -0
- package/dist/rich-text/rich-text.d.ts +106 -0
- package/dist/rich-text/rich-text.js +249 -0
- package/dist/rich-text/value.d.ts +55 -0
- package/dist/rich-text/value.js +126 -0
- package/dist/screen/client.d.ts +156 -0
- package/dist/screen/client.js +71 -0
- package/dist/screen/generate.d.ts +14 -0
- package/dist/screen/generate.js +268 -0
- package/dist/screen/index.d.ts +496 -0
- package/dist/screen/index.js +663 -0
- package/dist/screen/react.d.ts +97 -0
- package/dist/screen/react.js +58 -0
- package/dist/screen/studio.d.ts +24 -0
- package/dist/screen/studio.js +68 -0
- package/dist/service/index.d.ts +63 -0
- package/dist/service/index.js +15 -0
- package/dist/storage/allowed-type.d.ts +5 -0
- package/dist/storage/allowed-type.js +7 -0
- package/dist/storage/index.d.ts +42 -0
- package/dist/storage/index.js +43 -0
- package/dist/storage/storage.d.ts +386 -0
- package/dist/storage/storage.js +412 -0
- package/dist/targets.d.ts +14 -0
- package/dist/targets.js +16 -0
- package/dist/versions/index.d.ts +37 -0
- package/dist/versions/index.js +8 -0
- package/dist/versions/versions.d.ts +104 -0
- package/dist/versions/versions.js +160 -0
- package/dist/vite.d.ts +7 -0
- package/dist/vite.js +81 -0
- package/dist/zod/index.d.ts +193 -0
- package/dist/zod/index.js +122 -0
- package/dist/zod/kinds.d.ts +36 -0
- package/dist/zod/kinds.js +58 -0
- package/dist/zod/rules.d.ts +117 -0
- package/dist/zod/rules.js +67 -0
- package/docs/packages/mithaq/README.md +962 -0
- package/docs/packages/mithaq/src/asas/cli/README.md +252 -0
- package/docs/packages/mithaq/src/asas/runner/README.md +472 -0
- package/docs/packages/mithaq/src/drizzle/README.md +39 -0
- package/docs/packages/mithaq-admin/README.md +312 -0
- package/docs/templates/asas/README.md +1056 -0
- package/package.json +92 -4
- package/skills/add-field/SKILL.md +27 -0
- package/skills/add-kayan/SKILL.md +26 -0
- package/skills/eject-admin-piece/SKILL.md +28 -0
- package/skills/upgrade-mithaq/SKILL.md +35 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { integer, text, uuid } from 'drizzle-orm/pg-core';
|
|
2
|
+
import type { ResolvedField } from '../mithaq/types.ts';
|
|
3
|
+
import type { ColumnBuilder } from './index.ts';
|
|
4
|
+
/** Length is a rule, not a kind: without a maximum a string column is `text`. */
|
|
5
|
+
declare const string: (field: ResolvedField) => import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]> | import("drizzle-orm/pg-core").PgVarcharBuilder<[string, ...string[]]>;
|
|
6
|
+
declare const idColumns: {
|
|
7
|
+
number: typeof integer;
|
|
8
|
+
text: typeof text;
|
|
9
|
+
uuid: typeof uuid;
|
|
10
|
+
};
|
|
11
|
+
export declare const idKinds: (keyof typeof idColumns)[];
|
|
12
|
+
/** One column builder per kind. */
|
|
13
|
+
export declare const kinds: {
|
|
14
|
+
number: (field: ResolvedField) => import("drizzle-orm/pg-core").PgNumericNumberBuilder | import("drizzle-orm/pg-core").PgSerialBuilder;
|
|
15
|
+
integer: (field: ResolvedField) => import("drizzle-orm/pg-core").PgIntegerBuilder;
|
|
16
|
+
decimal: (field: ResolvedField) => import("drizzle-orm/pg-core").PgNumericBuilder;
|
|
17
|
+
text: typeof string;
|
|
18
|
+
email: typeof string;
|
|
19
|
+
checkbox: (field: ResolvedField) => import("drizzle-orm/pg-core").PgBooleanBuilder;
|
|
20
|
+
textArray: (field: ResolvedField) => import("drizzle-orm/pg-core").SetDimensions<import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>, 1>;
|
|
21
|
+
uuid: (field: ResolvedField) => import("drizzle-orm/pg-core").PgUUIDBuilder;
|
|
22
|
+
datetime: (field: ResolvedField) => import("drizzle-orm/pg-core").PgTimestampBuilder;
|
|
23
|
+
date: (field: ResolvedField) => import("drizzle-orm/pg-core").PgDateStringBuilder;
|
|
24
|
+
join: (field: ResolvedField) => never;
|
|
25
|
+
json: (field: ResolvedField) => import("drizzle-orm/pg-core").PgJsonbBuilder;
|
|
26
|
+
relationship: ColumnBuilder;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { boolean, date, integer, jsonb, numeric, serial, text, timestamp, uuid, varchar } from 'drizzle-orm/pg-core';
|
|
2
|
+
/** Length is a rule, not a kind: without a maximum a string column is `text`. */
|
|
3
|
+
const string = (field) => typeof field.rules?.maxLength !== 'number'
|
|
4
|
+
? text(field.column)
|
|
5
|
+
: varchar(field.column, { length: field.rules.maxLength });
|
|
6
|
+
// A foreign key takes the type of the id it points at: Postgres refuses a
|
|
7
|
+
// `text` column referencing a `uuid` key. The keys are the kinds an id may be.
|
|
8
|
+
const idColumns = { number: integer, text, uuid };
|
|
9
|
+
export const idKinds = Object.keys(idColumns);
|
|
10
|
+
const idColumn = (field) => idColumns[field.target.fields.id.kind](field.column);
|
|
11
|
+
const relationship = (field, tables) => idColumn(field).references(() => tables[field.target.name].id, {
|
|
12
|
+
onDelete: ['cascade', 'restrict', 'set null'].includes(String(field.rules?.onDelete))
|
|
13
|
+
? field.rules?.onDelete
|
|
14
|
+
: undefined,
|
|
15
|
+
});
|
|
16
|
+
/** One column builder per kind. */
|
|
17
|
+
export const kinds = {
|
|
18
|
+
number: (field) => field.name === 'id' ? serial(field.column) : numeric(field.column, { mode: 'number' }),
|
|
19
|
+
integer: (field) => integer(field.column),
|
|
20
|
+
// drizzle's default string mode, so no digit passes through a JS number.
|
|
21
|
+
decimal: (field) => typeof field.rules?.precision === 'number'
|
|
22
|
+
? numeric(field.column, { precision: field.rules.precision, scale: field.rules.scale })
|
|
23
|
+
: numeric(field.column),
|
|
24
|
+
text: string,
|
|
25
|
+
email: string,
|
|
26
|
+
checkbox: (field) => boolean(field.column),
|
|
27
|
+
// Length is not a rule this kind binds, so it is never `varchar(n)[]`.
|
|
28
|
+
textArray: (field) => text(field.column).array(),
|
|
29
|
+
// Only the primary key gets a random default: any other uuid column holds an
|
|
30
|
+
// identifier something else chose.
|
|
31
|
+
uuid: (field) => (field.name === 'id' ? uuid(field.column).defaultRandom() : uuid(field.column)),
|
|
32
|
+
datetime: (field) => timestamp(field.column, { precision: 3, withTimezone: true, mode: 'date' }),
|
|
33
|
+
// `mode: 'string'` keeps the day a day: `'date'` mode hands back a `Date` at
|
|
34
|
+
// local midnight, which another zone reads as the day before.
|
|
35
|
+
date: (field) => date(field.column, { mode: 'string' }),
|
|
36
|
+
// Unreachable: `columnsOfField` answers a join with no column before any builder runs.
|
|
37
|
+
join: (field) => {
|
|
38
|
+
throw new Error(`Field "${field.name}" is a join, whose rows are held by kayan "${field.target?.name}", so this store builds no column for it.`);
|
|
39
|
+
},
|
|
40
|
+
// `jsonb`, as Payload's Postgres adapter stores a json field, so either reads what the other wrote.
|
|
41
|
+
json: (field) => jsonb(field.column),
|
|
42
|
+
relationship,
|
|
43
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import * as modules from 'node:module';
|
|
2
|
+
import { type NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
3
|
+
import { type ProdMigrations } from './index.ts';
|
|
4
|
+
import type { ResolvedKayan } from '../mithaq/types.ts';
|
|
5
|
+
export declare const binary: string;
|
|
6
|
+
/**
|
|
7
|
+
* Resolves each drizzle-orm import made under `kit` from `from` instead. drizzle-kit imports
|
|
8
|
+
* drizzle-orm without declaring it, so on its own it loads whatever copy the project hoists,
|
|
9
|
+
* such as a 0.45 beside the one the tables were built with, and fails on it.
|
|
10
|
+
*/
|
|
11
|
+
export declare const holdKitOrm: ({ kit, from }: {
|
|
12
|
+
kit: string;
|
|
13
|
+
from: string;
|
|
14
|
+
}) => modules.ModuleHooks;
|
|
15
|
+
/** The drizzle-kit this mithaq installs, and the file its drizzle-orm resolves from. */
|
|
16
|
+
export declare const ownKit: {
|
|
17
|
+
kit: string;
|
|
18
|
+
from: string;
|
|
19
|
+
};
|
|
20
|
+
/** Holds this mithaq's drizzle-kit to its own drizzle-orm in this process, once. */
|
|
21
|
+
export declare const holdOwnKit: () => {};
|
|
22
|
+
/**
|
|
23
|
+
* A module to `--import` that holds `kit`'s drizzle-orm to `from`'s in a child process.
|
|
24
|
+
* ponytail: only the drizzle-kit mithaq starts is held; `drizzle-kit migrate` run by hand beside a
|
|
25
|
+
* second drizzle-orm still loads the hoisted one. Ship a `mithaq` word that applies migrations if that bites.
|
|
26
|
+
*/
|
|
27
|
+
export declare const kitOrm: (held: {
|
|
28
|
+
kit: string;
|
|
29
|
+
from: string;
|
|
30
|
+
}) => string;
|
|
31
|
+
export declare const header = "// Written by `mithaq migrate`. Commit it.";
|
|
32
|
+
/** One `unresolved` item, and one reply in the hints file, are the same shape. */
|
|
33
|
+
type Hint = {
|
|
34
|
+
type: string;
|
|
35
|
+
kind: string;
|
|
36
|
+
entity: string[];
|
|
37
|
+
reason?: string;
|
|
38
|
+
};
|
|
39
|
+
type Envelope = {
|
|
40
|
+
status: 'ok';
|
|
41
|
+
migration_path?: string;
|
|
42
|
+
statements?: Statement[];
|
|
43
|
+
} | {
|
|
44
|
+
status: 'no_changes';
|
|
45
|
+
} | {
|
|
46
|
+
status: 'missing_hints';
|
|
47
|
+
unresolved: Hint[];
|
|
48
|
+
} | {
|
|
49
|
+
status: 'error';
|
|
50
|
+
error: {
|
|
51
|
+
code: string;
|
|
52
|
+
source?: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
type Statement = {
|
|
56
|
+
type: 'drop_table';
|
|
57
|
+
table: {
|
|
58
|
+
schema: string;
|
|
59
|
+
name: string;
|
|
60
|
+
};
|
|
61
|
+
} | {
|
|
62
|
+
type: 'drop_column';
|
|
63
|
+
column: {
|
|
64
|
+
schema: string;
|
|
65
|
+
table: string;
|
|
66
|
+
name: string;
|
|
67
|
+
};
|
|
68
|
+
} | {
|
|
69
|
+
type: 'drop_pk';
|
|
70
|
+
pk: {
|
|
71
|
+
schema?: string;
|
|
72
|
+
table: string;
|
|
73
|
+
name: string;
|
|
74
|
+
};
|
|
75
|
+
} | {
|
|
76
|
+
type: 'drop_view';
|
|
77
|
+
view: {
|
|
78
|
+
schema: string;
|
|
79
|
+
name: string;
|
|
80
|
+
materialized?: boolean;
|
|
81
|
+
};
|
|
82
|
+
} | {
|
|
83
|
+
type: 'recreate_column';
|
|
84
|
+
diff: {
|
|
85
|
+
$right: {
|
|
86
|
+
schema: string;
|
|
87
|
+
table: string;
|
|
88
|
+
name: string;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
} | {
|
|
92
|
+
type: string;
|
|
93
|
+
};
|
|
94
|
+
type Losing = {
|
|
95
|
+
kind: 'table' | 'column' | 'primary_key' | 'view';
|
|
96
|
+
entity: string[];
|
|
97
|
+
};
|
|
98
|
+
export declare const droppedBy: (statement: Statement) => Losing | undefined;
|
|
99
|
+
/** A guard the database enforces and a migration would drop, in the shape its reply names it. */
|
|
100
|
+
type Guarded = {
|
|
101
|
+
kind: 'check' | 'enum' | 'column' | 'sequence';
|
|
102
|
+
entity: string[];
|
|
103
|
+
};
|
|
104
|
+
export declare const guardDroppedBy: (statement: Statement) => Guarded | undefined;
|
|
105
|
+
type Database = {
|
|
106
|
+
execute(query: unknown): Promise<{
|
|
107
|
+
rows: unknown[];
|
|
108
|
+
}>;
|
|
109
|
+
transaction<T>(run: (tx: {
|
|
110
|
+
execute(query: unknown): Promise<{
|
|
111
|
+
rows: unknown[];
|
|
112
|
+
}>;
|
|
113
|
+
}) => Promise<T>, config?: {
|
|
114
|
+
accessMode?: 'read only';
|
|
115
|
+
}): Promise<T>;
|
|
116
|
+
};
|
|
117
|
+
export declare const bootMigrations: ({ db, prodMigrations }: {
|
|
118
|
+
db: NodePgDatabase;
|
|
119
|
+
prodMigrations: ProdMigrations | undefined;
|
|
120
|
+
}) => Promise<void>;
|
|
121
|
+
type Pulled = {
|
|
122
|
+
status: 'ok';
|
|
123
|
+
migrationPath: string;
|
|
124
|
+
snapshotPath: string;
|
|
125
|
+
} | {
|
|
126
|
+
status: 'error';
|
|
127
|
+
error: {
|
|
128
|
+
code: string;
|
|
129
|
+
source?: string;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
export declare const baselineOf: ({ envelope, read, tables }: {
|
|
133
|
+
envelope: Pulled;
|
|
134
|
+
read: (path: string) => string;
|
|
135
|
+
/** The language's tables as `<schema>.<name>`. */
|
|
136
|
+
tables: readonly string[];
|
|
137
|
+
}) => {
|
|
138
|
+
folder: string;
|
|
139
|
+
sql: string;
|
|
140
|
+
snapshot: string;
|
|
141
|
+
};
|
|
142
|
+
export declare const statementsOf: (envelope: Envelope) => Statement[];
|
|
143
|
+
type Target = {
|
|
144
|
+
db: Database;
|
|
145
|
+
tables: Record<string, unknown>;
|
|
146
|
+
schemas: Record<string, unknown>;
|
|
147
|
+
enums: Record<string, {
|
|
148
|
+
schema?: string;
|
|
149
|
+
enumName: string;
|
|
150
|
+
enumValues: string[];
|
|
151
|
+
}>;
|
|
152
|
+
connectionString?: string;
|
|
153
|
+
kayan: readonly ResolvedKayan[];
|
|
154
|
+
};
|
|
155
|
+
export declare const run: ({ target, flags, }: {
|
|
156
|
+
target: Target;
|
|
157
|
+
flags: readonly string[];
|
|
158
|
+
}) => Promise<number>;
|
|
159
|
+
export {};
|