@oktis-works/database 0.1.11 → 0.1.13
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/connection.d.ts +12 -3
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/migrations/seed.d.ts +51 -0
- package/dist/migrations/seed.d.ts.map +1 -0
- package/dist/migrations/seed.js +68 -0
- package/dist/migrations/seed.js.map +1 -0
- package/package.json +3 -3
package/dist/connection.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import postgres from 'postgres';
|
|
2
2
|
import type { DatabaseConfig } from '@oktis-works/config';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* `sql` do driver com `unsafe` alargado: o tipo original exige `JSONValue` nos
|
|
5
|
+
* parâmetros, mas em runtime o driver serializa sozinho (string/object/array/
|
|
6
|
+
* number → jsonb — boolean via CASE WHEN no settings). Restringir a JSONValue
|
|
7
|
+
* só gera ruído de tipo em queries raw, onde os params já são `unknown`.
|
|
8
|
+
*/
|
|
9
|
+
export type RepoSql = postgres.Sql & {
|
|
10
|
+
unsafe<T extends any[] = postgres.Row[]>(query: string, parameters?: any[], queryOptions?: any): postgres.PendingQuery<T>;
|
|
11
|
+
};
|
|
12
|
+
export declare function createConnection(config: DatabaseConfig): RepoSql;
|
|
13
|
+
export declare function getConnection(): RepoSql;
|
|
5
14
|
/** Conexão de leitura — usa replica se configurada, senão primary (transparente). */
|
|
6
|
-
export declare function getReadConnection():
|
|
15
|
+
export declare function getReadConnection(): RepoSql;
|
|
7
16
|
export declare function getDriver(): DatabaseConfig['driver'];
|
|
8
17
|
export declare function closeConnection(): Promise<void>;
|
|
9
18
|
export declare function healthCheck(): Promise<boolean>;
|
package/dist/connection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAKA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAKA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,GAAG;IACnC,MAAM,CAAC,CAAC,SAAS,GAAG,EAAE,GAAG,QAAQ,CAAC,GAAG,EAAE,EACrC,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,GAAG,EAAE,EAClB,YAAY,CAAC,EAAE,GAAG,GACjB,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CAC7B,CAAC;AAMF,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAsChE;AAED,wBAAgB,aAAa,IAAI,OAAO,CAGvC;AAED,qFAAqF;AACrF,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED,wBAAgB,SAAS,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAoB;AAEzE,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAKrD;AAED,wBAAsB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAQpD"}
|
package/dist/connection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,sEAAsE;AACtE,oFAAoF;AACpF,wGAAwG;AAExG,OAAO,QAAQ,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","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,MAAM,CAAC,GAAG;YACf,GAAG,EAAE,MAAM,CAAC,cAAc;YAC1B,YAAY,EAAE,EAAE;YAChB,eAAe,EAAE,EAAE;SACpB,CAAY,CAAC;IAChB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IAClG,OAAO,IAAI,CAAC;AACd,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,iBAAiB;IAC/B,OAAO,WAAW,IAAI,aAAa,EAAE,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,SAAS,KAA+B,OAAO,OAAO,CAAC,CAAC,CAAC;AAEzE,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,IAAI,IAAI,EAAE,CAAC;QACT,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;QACjB,IAAI,GAAG,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,aAAa,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,MAAM,GAAG,CAAA,gBAAgB,CAAC;QACzC,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ export { createConnection, getConnection, closeConnection, healthCheck } from '.
|
|
|
2
2
|
export { setTenantContext, clearTenantContext, getCurrentTenantId, enableRLS } from './rls/index.js';
|
|
3
3
|
export { loadMigrationsFromDir, getAppliedMigrations, applyMigration, rollbackMigration, runMigrations, runPluginMigrations, rollbackPluginMigrations, type MigrationFile, } from './migrations/runner.js';
|
|
4
4
|
export { ensureCoreSchema, resolveTenantId } from './migrations/bootstrap.js';
|
|
5
|
+
export { seedCoreData, seedDefaultRoles, seedDefaultSettings, DEFAULT_ROLES, DEFAULT_SETTINGS, } from './migrations/seed.js';
|
|
5
6
|
export { schema, getSchema } from './schema/index.js';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACrG,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,wBAAwB,EACxB,KAAK,aAAa,GACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACrG,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,wBAAwB,EACxB,KAAK,aAAa,GACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,5 +3,6 @@ export { createConnection, getConnection, closeConnection, healthCheck } from '.
|
|
|
3
3
|
export { setTenantContext, clearTenantContext, getCurrentTenantId, enableRLS } from './rls/index.js';
|
|
4
4
|
export { loadMigrationsFromDir, getAppliedMigrations, applyMigration, rollbackMigration, runMigrations, runPluginMigrations, rollbackPluginMigrations, } from './migrations/runner.js';
|
|
5
5
|
export { ensureCoreSchema, resolveTenantId } from './migrations/bootstrap.js';
|
|
6
|
+
export { seedCoreData, seedDefaultRoles, seedDefaultSettings, DEFAULT_ROLES, DEFAULT_SETTINGS, } from './migrations/seed.js';
|
|
6
7
|
export { schema, getSchema } from './schema/index.js';
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACrG,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,wBAAwB,GAEzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACrG,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,wBAAwB,GAEzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type postgres from 'postgres';
|
|
2
|
+
type Sql = postgres.Sql;
|
|
3
|
+
/** Roles canônicas — DEVEM casar com os slugs do DEFAULT_POLICY do auth. */
|
|
4
|
+
export declare const DEFAULT_ROLES: readonly [{
|
|
5
|
+
readonly name: "Super Admin";
|
|
6
|
+
readonly slug: "SUPER_ADMIN";
|
|
7
|
+
}, {
|
|
8
|
+
readonly name: "Administrador";
|
|
9
|
+
readonly slug: "TENANT_ADMIN";
|
|
10
|
+
}, {
|
|
11
|
+
readonly name: "Editor";
|
|
12
|
+
readonly slug: "EDITOR";
|
|
13
|
+
}, {
|
|
14
|
+
readonly name: "Autor";
|
|
15
|
+
readonly slug: "AUTHOR";
|
|
16
|
+
}, {
|
|
17
|
+
readonly name: "Leitor";
|
|
18
|
+
readonly slug: "VIEWER";
|
|
19
|
+
}];
|
|
20
|
+
/** Settings iniciais do grupo `general` (form de Settings → General da admin). */
|
|
21
|
+
export declare const DEFAULT_SETTINGS: readonly [{
|
|
22
|
+
readonly key: "siteTitle";
|
|
23
|
+
readonly value: "Meu Site";
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
}, {
|
|
26
|
+
readonly key: "siteDescription";
|
|
27
|
+
readonly value: "Um novo site feito com OkCMS";
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
}, {
|
|
30
|
+
readonly key: "language";
|
|
31
|
+
readonly value: "pt-BR";
|
|
32
|
+
readonly type: "string";
|
|
33
|
+
}, {
|
|
34
|
+
readonly key: "timezone";
|
|
35
|
+
readonly value: "America/Sao_Paulo";
|
|
36
|
+
readonly type: "string";
|
|
37
|
+
}];
|
|
38
|
+
/** Cria (se faltar) as roles globais (tenant_id NULL) da política. Retorna qtd criada. */
|
|
39
|
+
export declare function seedDefaultRoles(sql?: Sql): Promise<number>;
|
|
40
|
+
/** Cria (se faltar) os settings iniciais no tenant dado. Retorna qtd criada. */
|
|
41
|
+
export declare function seedDefaultSettings(tenantId: string, sql?: Sql): Promise<number>;
|
|
42
|
+
/**
|
|
43
|
+
* Seed completo (roles + settings do tenant default). Idempotente — usar em
|
|
44
|
+
* `db:migrate`/`seed` da CLI e como fallback no registro do primeiro usuário.
|
|
45
|
+
*/
|
|
46
|
+
export declare function seedCoreData(sql?: Sql): Promise<{
|
|
47
|
+
roles: number;
|
|
48
|
+
settings: number;
|
|
49
|
+
}>;
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=seed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../src/migrations/seed.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAErC,KAAK,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC;AAExB,4EAA4E;AAC5E,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;EAMhB,CAAC;AAEX,kFAAkF;AAClF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;EAKnB,CAAC;AAEX,0FAA0F;AAC1F,wBAAsB,gBAAgB,CAAC,GAAG,GAAE,GAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBlF;AAED,gFAAgF;AAChF,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,EAChB,GAAG,GAAE,GAAqB,GACzB,OAAO,CAAC,MAAM,CAAC,CAejB;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAChC,GAAG,GAAE,GAAqB,GACzB,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAK9C"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// @oktis-works/database - Seeds de dados padrão (roles + settings)
|
|
2
|
+
//
|
|
3
|
+
// - As 5 roles do DEFAULT_POLICY do @oktis-works/auth precisam EXISTIR no
|
|
4
|
+
// banco: o JWT carrega só os slugs (lidos de roles via tenant_users) e sem
|
|
5
|
+
// a linha da role o usuário nasce sem papel → 403 em toda rota protegida
|
|
6
|
+
// (registrava, logava, mas não operava nada).
|
|
7
|
+
// - Settings do grupo `general` para o admin ter o que editar (a tabela
|
|
8
|
+
// nasce vazia).
|
|
9
|
+
//
|
|
10
|
+
// Idempotente: roda em QUALQUER banco (fresco ou existente) sem duplicar —
|
|
11
|
+
// roles via WHERE NOT EXISTS, settings via ON CONFLICT (UNIQUE(key,tenant)).
|
|
12
|
+
import { getConnection } from '../connection.js';
|
|
13
|
+
import { resolveTenantId } from './bootstrap.js';
|
|
14
|
+
/** Roles canônicas — DEVEM casar com os slugs do DEFAULT_POLICY do auth. */
|
|
15
|
+
export const DEFAULT_ROLES = [
|
|
16
|
+
{ name: 'Super Admin', slug: 'SUPER_ADMIN' },
|
|
17
|
+
{ name: 'Administrador', slug: 'TENANT_ADMIN' },
|
|
18
|
+
{ name: 'Editor', slug: 'EDITOR' },
|
|
19
|
+
{ name: 'Autor', slug: 'AUTHOR' },
|
|
20
|
+
{ name: 'Leitor', slug: 'VIEWER' },
|
|
21
|
+
];
|
|
22
|
+
/** Settings iniciais do grupo `general` (form de Settings → General da admin). */
|
|
23
|
+
export const DEFAULT_SETTINGS = [
|
|
24
|
+
{ key: 'siteTitle', value: 'Meu Site', type: 'string' },
|
|
25
|
+
{ key: 'siteDescription', value: 'Um novo site feito com OkCMS', type: 'string' },
|
|
26
|
+
{ key: 'language', value: 'pt-BR', type: 'string' },
|
|
27
|
+
{ key: 'timezone', value: 'America/Sao_Paulo', type: 'string' },
|
|
28
|
+
];
|
|
29
|
+
/** Cria (se faltar) as roles globais (tenant_id NULL) da política. Retorna qtd criada. */
|
|
30
|
+
export async function seedDefaultRoles(sql = getConnection()) {
|
|
31
|
+
let inserted = 0;
|
|
32
|
+
for (const role of DEFAULT_ROLES) {
|
|
33
|
+
// Cast explícito: $2 aparece em dois contextos (valor de inserção e
|
|
34
|
+
// comparação de coluna) — sem cast o Postgres deduz tipos diferentes
|
|
35
|
+
// para o mesmo parâmetro e falha com "inconsistent types deduced".
|
|
36
|
+
const rows = await sql.unsafe(`INSERT INTO roles (name, slug, is_system, permissions)
|
|
37
|
+
SELECT $1::varchar, $2::varchar, true, '[]'::jsonb
|
|
38
|
+
WHERE NOT EXISTS (SELECT 1 FROM roles WHERE slug = $2::varchar AND tenant_id IS NULL)
|
|
39
|
+
RETURNING id`, [role.name, role.slug]);
|
|
40
|
+
inserted += rows.length;
|
|
41
|
+
}
|
|
42
|
+
return inserted;
|
|
43
|
+
}
|
|
44
|
+
/** Cria (se faltar) os settings iniciais no tenant dado. Retorna qtd criada. */
|
|
45
|
+
export async function seedDefaultSettings(tenantId, sql = getConnection()) {
|
|
46
|
+
let inserted = 0;
|
|
47
|
+
for (const s of DEFAULT_SETTINGS) {
|
|
48
|
+
// RETURNING: sem ele o driver devolve [] mesmo com insert bem-sucedido
|
|
49
|
+
// (contaria 0 no log e quebraria a detecção de idempotência).
|
|
50
|
+
const rows = await sql.unsafe(`INSERT INTO settings (tenant_id, key, value, "group", type)
|
|
51
|
+
VALUES ($1, $2, to_jsonb($3::text), 'general', $4)
|
|
52
|
+
ON CONFLICT (key, tenant_id) DO NOTHING
|
|
53
|
+
RETURNING id`, [tenantId, s.key, s.value, s.type]);
|
|
54
|
+
inserted += rows.length;
|
|
55
|
+
}
|
|
56
|
+
return inserted;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Seed completo (roles + settings do tenant default). Idempotente — usar em
|
|
60
|
+
* `db:migrate`/`seed` da CLI e como fallback no registro do primeiro usuário.
|
|
61
|
+
*/
|
|
62
|
+
export async function seedCoreData(sql = getConnection()) {
|
|
63
|
+
const roles = await seedDefaultRoles(sql);
|
|
64
|
+
const tenantId = await resolveTenantId('default');
|
|
65
|
+
const settings = await seedDefaultSettings(tenantId, sql);
|
|
66
|
+
return { roles, settings };
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=seed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.js","sourceRoot":"","sources":["../../src/migrations/seed.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,2EAA2E;AAC3E,gDAAgD;AAChD,wEAAwE;AACxE,kBAAkB;AAClB,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAE7E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAKjD,4EAA4E;AAC5E,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,aAAa,EAAE;IAC5C,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,cAAc,EAAE;IAC/C,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;IAClC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE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AAC,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CACnC,CAAC;QACF,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC;IAC1B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAW,aAAa,EAAE;IAE1B,MAAM,KAAK,GAAG,MAAM,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,SAAS,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC1D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC7B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oktis-works/database",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"db:rollback": "node --loader ts-node/esm src/migrations/runner.ts rollback"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@oktis-works/types": "^0.1.
|
|
23
|
-
"@oktis-works/config": "^0.1.
|
|
22
|
+
"@oktis-works/types": "^0.1.13",
|
|
23
|
+
"@oktis-works/config": "^0.1.13",
|
|
24
24
|
"postgres": "3.4.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|