@murumets-ee/settings 0.1.4 → 0.1.6
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/admin.d.mts +72 -0
- package/dist/admin.d.mts.map +1 -0
- package/dist/admin.mjs +2 -0
- package/dist/admin.mjs.map +1 -0
- package/dist/client-factory-f4nNDWaD.mjs +2 -0
- package/dist/client-factory-f4nNDWaD.mjs.map +1 -0
- package/dist/index.d.mts +224 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/plugin.d.mts +7 -0
- package/dist/plugin.d.mts.map +1 -0
- package/dist/{plugin.js → plugin.mjs} +3 -2
- package/dist/plugin.mjs.map +1 -0
- package/dist/schema.d.mts +318 -0
- package/dist/schema.d.mts.map +1 -0
- package/dist/schema.mjs +2 -0
- package/dist/schema.mjs.map +1 -0
- package/dist/view-state.d.mts +48 -0
- package/dist/view-state.d.mts.map +1 -0
- package/dist/view-state.mjs +2 -0
- package/dist/view-state.mjs.map +1 -0
- package/package.json +17 -17
- package/dist/admin.d.ts +0 -100
- package/dist/admin.js +0 -1
- package/dist/chunk-E3K4GXDC.js +0 -1
- package/dist/client-factory-OGWK5MKO.js +0 -1
- package/dist/index.d.ts +0 -291
- package/dist/index.js +0 -1
- package/dist/plugin.d.ts +0 -22
- package/dist/schema.d.ts +0 -316
- package/dist/schema.js +0 -1
- package/dist/view-state.d.ts +0 -68
- package/dist/view-state.js +0 -1
package/dist/index.d.ts
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { ZodType } from 'zod';
|
|
2
|
-
import { Logger, ToolkitApp } from '@murumets-ee/core';
|
|
3
|
-
import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Setting configuration types and compile-time type inference.
|
|
7
|
-
*
|
|
8
|
-
* Design mirrors the entity field system:
|
|
9
|
-
* - Config interfaces define what each setting type accepts
|
|
10
|
-
* - SettingToTS maps a single config to its TypeScript type
|
|
11
|
-
* - InferSettingValue adds null awareness based on `default` presence
|
|
12
|
-
* - InferSettingsMap maps an entire schema to a typed record
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
interface BaseSettingConfig {
|
|
16
|
-
/** Human-readable label for admin UI */
|
|
17
|
-
label?: string;
|
|
18
|
-
/** Description / help text */
|
|
19
|
-
description?: string;
|
|
20
|
-
/** If true, this setting can have per-locale values (mirrors entity translatable pattern) */
|
|
21
|
-
translatable?: boolean;
|
|
22
|
-
}
|
|
23
|
-
interface TextSettingConfig extends BaseSettingConfig {
|
|
24
|
-
type: 'text';
|
|
25
|
-
default?: string;
|
|
26
|
-
maxLength?: number;
|
|
27
|
-
minLength?: number;
|
|
28
|
-
pattern?: RegExp;
|
|
29
|
-
}
|
|
30
|
-
interface NumberSettingConfig extends BaseSettingConfig {
|
|
31
|
-
type: 'number';
|
|
32
|
-
default?: number;
|
|
33
|
-
min?: number;
|
|
34
|
-
max?: number;
|
|
35
|
-
integer?: boolean;
|
|
36
|
-
}
|
|
37
|
-
interface BooleanSettingConfig extends BaseSettingConfig {
|
|
38
|
-
type: 'boolean';
|
|
39
|
-
default?: boolean;
|
|
40
|
-
}
|
|
41
|
-
interface SelectSettingConfig<O extends readonly string[] = readonly string[]> extends BaseSettingConfig {
|
|
42
|
-
type: 'select';
|
|
43
|
-
options: O;
|
|
44
|
-
default?: O[number];
|
|
45
|
-
}
|
|
46
|
-
interface JsonSettingConfig<T = unknown> extends BaseSettingConfig {
|
|
47
|
-
type: 'json';
|
|
48
|
-
default?: T;
|
|
49
|
-
/** Optional Zod schema for validation. If provided, values are validated on set. */
|
|
50
|
-
schema?: ZodType<T>;
|
|
51
|
-
}
|
|
52
|
-
interface MediaSettingConfig extends BaseSettingConfig {
|
|
53
|
-
type: 'media';
|
|
54
|
-
accept?: string[];
|
|
55
|
-
}
|
|
56
|
-
type SettingConfig = TextSettingConfig | NumberSettingConfig | BooleanSettingConfig | SelectSettingConfig | JsonSettingConfig | MediaSettingConfig;
|
|
57
|
-
/**
|
|
58
|
-
* Maps a single SettingConfig to its TypeScript output type.
|
|
59
|
-
* Each branch is a shallow comparison — no recursion.
|
|
60
|
-
*/
|
|
61
|
-
type SettingToTS<S extends SettingConfig> = S extends TextSettingConfig ? string : S extends NumberSettingConfig ? number : S extends BooleanSettingConfig ? boolean : S extends SelectSettingConfig<infer O> ? O[number] : S extends JsonSettingConfig<infer T> ? T : S extends MediaSettingConfig ? string : never;
|
|
62
|
-
/**
|
|
63
|
-
* If a setting has a `default`, get() never returns null.
|
|
64
|
-
* Without a default, it returns T | null.
|
|
65
|
-
*/
|
|
66
|
-
type InferSettingValue<S extends SettingConfig> = S extends {
|
|
67
|
-
default: unknown;
|
|
68
|
-
} ? SettingToTS<S> : SettingToTS<S> | null;
|
|
69
|
-
type InferSettingsMap<Schema extends Record<string, SettingConfig>> = {
|
|
70
|
-
[K in keyof Schema]: InferSettingValue<Schema[K]>;
|
|
71
|
-
};
|
|
72
|
-
type SettingScope = 'global' | 'team' | 'user';
|
|
73
|
-
/** Sentinel value for global scope_id (avoids NULL uniqueness issues) */
|
|
74
|
-
declare const GLOBAL_SCOPE_ID = "__global__";
|
|
75
|
-
/** Sentinel value for locale column when no locale is specified (base/default value) */
|
|
76
|
-
declare const DEFAULT_LOCALE = "_default";
|
|
77
|
-
interface SettingsDefinition<S extends Record<string, SettingConfig> = Record<string, SettingConfig>> {
|
|
78
|
-
/** Unique namespace for this settings group */
|
|
79
|
-
namespace: string;
|
|
80
|
-
/** Default scope for these settings */
|
|
81
|
-
scope: SettingScope;
|
|
82
|
-
/** Setting schema (the shape) */
|
|
83
|
-
schema: S;
|
|
84
|
-
/** Human-readable label for admin UI */
|
|
85
|
-
label?: string;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Fluent API for building setting definitions.
|
|
90
|
-
*
|
|
91
|
-
* Each builder uses a `const` generic parameter on the config to preserve
|
|
92
|
-
* literal types (e.g., `default: 'My Site'` stays literal, not `string`).
|
|
93
|
-
* This enables compile-time type inference in the settings system.
|
|
94
|
-
*
|
|
95
|
-
* Pattern matches packages/entity/src/fields/builders.ts exactly.
|
|
96
|
-
*/
|
|
97
|
-
|
|
98
|
-
declare const setting: {
|
|
99
|
-
/**
|
|
100
|
-
* Text setting (string value)
|
|
101
|
-
*/
|
|
102
|
-
text: <const C extends Partial<Omit<TextSettingConfig, "type">> = {}>(config?: C) => TextSettingConfig & C;
|
|
103
|
-
/**
|
|
104
|
-
* Number setting
|
|
105
|
-
*/
|
|
106
|
-
number: <const C extends Partial<Omit<NumberSettingConfig, "type">> = {}>(config?: C) => NumberSettingConfig & C;
|
|
107
|
-
/**
|
|
108
|
-
* Boolean setting
|
|
109
|
-
*/
|
|
110
|
-
boolean: <const C extends Partial<Omit<BooleanSettingConfig, "type">> = {}>(config?: C) => BooleanSettingConfig & C;
|
|
111
|
-
/**
|
|
112
|
-
* Select setting (enum from options tuple)
|
|
113
|
-
* Preserves literal option types for type inference.
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* setting.select({ options: ['light', 'dark', 'system'] as const, default: 'system' })
|
|
117
|
-
* // inferred type: 'light' | 'dark' | 'system'
|
|
118
|
-
*/
|
|
119
|
-
select: <const O extends readonly string[], const C extends Partial<Omit<SelectSettingConfig, "type" | "options">> = {}>(config: {
|
|
120
|
-
options: O;
|
|
121
|
-
} & C) => SelectSettingConfig<O> & C;
|
|
122
|
-
/**
|
|
123
|
-
* JSON setting (arbitrary typed JSON)
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* setting.json<{ twitter?: string; github?: string }>()
|
|
127
|
-
* setting.json<string[]>({ default: [] })
|
|
128
|
-
*/
|
|
129
|
-
json: <T = unknown, const C extends Partial<Omit<JsonSettingConfig<T>, "type">> = {}>(config?: C) => JsonSettingConfig<T> & C;
|
|
130
|
-
/**
|
|
131
|
-
* Media setting (stores media ID as string UUID)
|
|
132
|
-
*/
|
|
133
|
-
media: <const C extends Partial<Omit<MediaSettingConfig, "type">> = {}>(config?: C) => MediaSettingConfig & C;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* SettingsClient — typed CRUD for key-value settings.
|
|
138
|
-
*
|
|
139
|
-
* Server-only. Uses read-write DB connection.
|
|
140
|
-
* Validates values against the setting schema on set().
|
|
141
|
-
*
|
|
142
|
-
* Supports per-locale values for settings marked `translatable: true`.
|
|
143
|
-
* Non-translatable settings always use the `__default__` locale.
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
* ```typescript
|
|
147
|
-
* import { createSettingsClient } from '@murumets-ee/settings'
|
|
148
|
-
* import { siteSettings } from './settings/site'
|
|
149
|
-
*
|
|
150
|
-
* const settings = createSettingsClient(siteSettings)
|
|
151
|
-
*
|
|
152
|
-
* // Default locale
|
|
153
|
-
* const name = await settings.get('siteName') // string (has default)
|
|
154
|
-
*
|
|
155
|
-
* // Locale-specific (only for translatable settings)
|
|
156
|
-
* const nameEt = await settings.get('siteName', { locale: 'et' })
|
|
157
|
-
*
|
|
158
|
-
* await settings.set('siteName', 'Mänguväljak', { locale: 'et' })
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
|
|
162
|
-
interface SettingsClientConfig {
|
|
163
|
-
/** Database client (read-write) */
|
|
164
|
-
db: PostgresJsDatabase;
|
|
165
|
-
/** Logger instance */
|
|
166
|
-
logger?: Logger;
|
|
167
|
-
/** Override scope (defaults to definition's scope) */
|
|
168
|
-
scope?: SettingScope;
|
|
169
|
-
/** Scope ID (required for team/user scope, defaults to '__global__' for global) */
|
|
170
|
-
scopeId?: string;
|
|
171
|
-
}
|
|
172
|
-
interface LocaleOption {
|
|
173
|
-
/** Locale code for translatable settings (e.g. 'et', 'ru'). Ignored for non-translatable settings. */
|
|
174
|
-
locale?: string;
|
|
175
|
-
}
|
|
176
|
-
declare class SettingsClient<S extends Record<string, SettingConfig> = Record<string, SettingConfig>> {
|
|
177
|
-
private definition;
|
|
178
|
-
private db;
|
|
179
|
-
private logger?;
|
|
180
|
-
private scope;
|
|
181
|
-
private scopeId;
|
|
182
|
-
private validators;
|
|
183
|
-
constructor(definition: SettingsDefinition<S>, config: SettingsClientConfig);
|
|
184
|
-
/**
|
|
185
|
-
* Get a single setting value.
|
|
186
|
-
*
|
|
187
|
-
* For translatable settings with a locale, tries locale-specific value first,
|
|
188
|
-
* then falls back to the default value, then the schema default, then null.
|
|
189
|
-
*/
|
|
190
|
-
get<K extends string & keyof S>(key: K, options?: LocaleOption): Promise<InferSettingValue<S[K]>>;
|
|
191
|
-
/**
|
|
192
|
-
* Get all settings for this namespace/scope as a typed object.
|
|
193
|
-
* Missing values are filled from schema defaults.
|
|
194
|
-
*
|
|
195
|
-
* When locale is specified, translatable settings prefer the locale-specific
|
|
196
|
-
* value over the default value.
|
|
197
|
-
*/
|
|
198
|
-
getAll(options?: LocaleOption): Promise<InferSettingsMap<S>>;
|
|
199
|
-
/**
|
|
200
|
-
* Set a single setting value.
|
|
201
|
-
* Validates against the schema before writing.
|
|
202
|
-
*
|
|
203
|
-
* Pass `{ locale }` to write a locale-specific value (only for translatable settings).
|
|
204
|
-
*/
|
|
205
|
-
set<K extends string & keyof S>(key: K, value: InferSettingValue<S[K]>, options?: LocaleOption): Promise<void>;
|
|
206
|
-
/**
|
|
207
|
-
* Set multiple settings at once (validated individually).
|
|
208
|
-
* Writes in a transaction — all or nothing.
|
|
209
|
-
*
|
|
210
|
-
* Pass `{ locale }` to write locale-specific values for translatable settings.
|
|
211
|
-
* Non-translatable settings in the values will always write to the default locale.
|
|
212
|
-
*/
|
|
213
|
-
setMany(values: Partial<InferSettingsMap<S>>, options?: LocaleOption): Promise<void>;
|
|
214
|
-
/**
|
|
215
|
-
* Delete a setting (resets to default on next get).
|
|
216
|
-
* Pass `{ locale }` to delete only the locale-specific value.
|
|
217
|
-
*/
|
|
218
|
-
delete<K extends string & keyof S>(key: K, options?: LocaleOption): Promise<void>;
|
|
219
|
-
/**
|
|
220
|
-
* Check if a setting has a stored value (not relying on default).
|
|
221
|
-
*/
|
|
222
|
-
has<K extends string & keyof S>(key: K, options?: LocaleOption): Promise<boolean>;
|
|
223
|
-
/**
|
|
224
|
-
* Resolve which locale to use for a given key.
|
|
225
|
-
* Non-translatable settings always use DEFAULT_LOCALE.
|
|
226
|
-
* Translatable settings use the requested locale or DEFAULT_LOCALE.
|
|
227
|
-
*/
|
|
228
|
-
private resolveLocale;
|
|
229
|
-
/** Base where conditions: namespace + scope + scopeId */
|
|
230
|
-
private baseWhere;
|
|
231
|
-
/** Full where clause for a specific key + locale */
|
|
232
|
-
private whereClause;
|
|
233
|
-
/** Upsert a single setting row */
|
|
234
|
-
private upsert;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Factory function for creating typed SettingsClient instances.
|
|
239
|
-
*
|
|
240
|
-
* Follows the createAdminClient(entity, app?) pattern from @murumets-ee/core.
|
|
241
|
-
*/
|
|
242
|
-
|
|
243
|
-
interface CreateSettingsClientOptions {
|
|
244
|
-
/** Override the toolkit app (defaults to getApp()) */
|
|
245
|
-
app?: ToolkitApp;
|
|
246
|
-
/** Override scope from definition */
|
|
247
|
-
scope?: SettingScope;
|
|
248
|
-
/** Scope ID for team/user scoped settings */
|
|
249
|
-
scopeId?: string;
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Create a typed SettingsClient.
|
|
253
|
-
*
|
|
254
|
-
* @example
|
|
255
|
-
* ```typescript
|
|
256
|
-
* import { createSettingsClient } from '@murumets-ee/settings'
|
|
257
|
-
* import { siteSettings } from './settings/site'
|
|
258
|
-
*
|
|
259
|
-
* const settings = createSettingsClient(siteSettings)
|
|
260
|
-
* const name = await settings.get('siteName') // string
|
|
261
|
-
* ```
|
|
262
|
-
*/
|
|
263
|
-
declare function createSettingsClient<S extends Record<string, SettingConfig>>(definition: SettingsDefinition<S>, options?: CreateSettingsClientOptions): SettingsClient<S>;
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Define a typed settings group.
|
|
267
|
-
*
|
|
268
|
-
* @example
|
|
269
|
-
* ```typescript
|
|
270
|
-
* import { defineSettings, setting } from '@murumets-ee/settings'
|
|
271
|
-
*
|
|
272
|
-
* export const siteSettings = defineSettings({
|
|
273
|
-
* namespace: 'site',
|
|
274
|
-
* scope: 'global',
|
|
275
|
-
* schema: {
|
|
276
|
-
* siteName: setting.text({ default: 'My Site' }),
|
|
277
|
-
* logo: setting.media(),
|
|
278
|
-
* maintenance: setting.boolean({ default: false }),
|
|
279
|
-
* },
|
|
280
|
-
* })
|
|
281
|
-
* ```
|
|
282
|
-
*/
|
|
283
|
-
|
|
284
|
-
declare function defineSettings<const S extends Record<string, SettingConfig>>(definition: {
|
|
285
|
-
namespace: string;
|
|
286
|
-
scope: SettingScope;
|
|
287
|
-
schema: S;
|
|
288
|
-
label?: string;
|
|
289
|
-
}): SettingsDefinition<S>;
|
|
290
|
-
|
|
291
|
-
export { type BaseSettingConfig, type BooleanSettingConfig, type CreateSettingsClientOptions, DEFAULT_LOCALE, GLOBAL_SCOPE_ID, type InferSettingValue, type InferSettingsMap, type JsonSettingConfig, type LocaleOption, type MediaSettingConfig, type NumberSettingConfig, type SelectSettingConfig, type SettingConfig, type SettingScope, type SettingToTS, SettingsClient, type SettingsClientConfig, type SettingsDefinition, type TextSettingConfig, createSettingsClient, defineSettings, setting };
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as t}from"./chunk-E3K4GXDC.js";import"server-only";var x={text:n=>({type:"text",...n}),number:n=>({type:"number",...n}),boolean:n=>({type:"boolean",...n}),select:n=>({type:"select",...n}),json:n=>({type:"json",...n}),media:n=>({type:"media",...n})};import{and as u,eq as l,or as h}from"drizzle-orm";var m="__global__",f="_default";import{z as d}from"zod";function y(n){switch(n.type){case"text":{let e=d.string();return n.maxLength&&(e=e.max(n.maxLength)),n.minLength&&(e=e.min(n.minLength)),n.pattern&&(e=e.regex(n.pattern)),e}case"number":{let e=d.number();return n.integer&&(e=e.int()),n.min!==void 0&&(e=e.min(n.min)),n.max!==void 0&&(e=e.max(n.max)),e}case"boolean":return d.boolean();case"select":return d.enum(n.options);case"json":return n.schema??d.unknown();case"media":return d.string().uuid();default:return d.unknown()}}function C(n){let e={};for(let[i,o]of Object.entries(n.schema)){let a=y(o);"default"in o&&o.default!==void 0||(a=a.nullable()),e[i]=a}return e}var S=class{definition;db;logger;scope;scopeId;validators;constructor(e,i){if(typeof window<"u")throw new Error("SettingsClient cannot be used in browser code.");if(this.definition=e,this.db=i.db,this.logger=i.logger,this.scope=i.scope??e.scope,this.scopeId=i.scopeId??m,(this.scope==="team"||this.scope==="user")&&!i.scopeId)throw new Error(`scopeId is required for ${this.scope}-scoped settings (namespace: ${e.namespace})`);this.validators=C(e)}async get(e,i){let o=this.definition.schema[e],a=o?.translatable&&i?.locale?i.locale:null;if(this.logger?.debug({namespace:this.definition.namespace,key:e,locale:a},"Getting setting"),a){let s=await this.db.select({locale:t.locale,value:t.value}).from(t).where(u(...this.baseWhere(),l(t.key,e),h(l(t.locale,a),l(t.locale,f)))),r=s.find(p=>p.locale===a),c=s.find(p=>p.locale===f),g=r??c;if(g&&g.value!==void 0&&g.value!==null)return g.value}else{let s=await this.db.select({value:t.value}).from(t).where(this.whereClause(e)).limit(1);if(s.length>0&&s[0].value!==void 0&&s[0].value!==null)return s[0].value}return o&&"default"in o&&o.default!==void 0?o.default:null}async getAll(e){let i=e?.locale??null;this.logger?.debug({namespace:this.definition.namespace,locale:i},"Getting all settings");let o;i?o=await this.db.select({key:t.key,locale:t.locale,value:t.value}).from(t).where(u(...this.baseWhere(),h(l(t.locale,f),l(t.locale,i)))):o=await this.db.select({key:t.key,locale:t.locale,value:t.value}).from(t).where(u(...this.baseWhere(),l(t.locale,f)));let a=new Map;for(let r of o){let c=a.get(r.key)??{};r.locale===f?c.default=r.value:c.locale=r.value,a.set(r.key,c)}let s={};for(let[r,c]of Object.entries(this.definition.schema)){let g=a.get(r),p;c.translatable&&i&&g?.locale!==void 0&&g?.locale!==null?p=g.locale:g?.default!==void 0&&g?.default!==null&&(p=g.default),p!==void 0?s[r]=p:"default"in c&&c.default!==void 0?s[r]=c.default:s[r]=null}return s}async set(e,i,o){let a=this.resolveLocale(e,o);if(this.logger?.info({namespace:this.definition.namespace,key:e,locale:a},"Setting value"),!(e in this.definition.schema))throw new Error(`Unknown setting key '${e}' in namespace '${this.definition.namespace}'`);let s=this.validators[e];s&&s.parse(i),await this.upsert(e,i,a)}async setMany(e,i){this.logger?.info({namespace:this.definition.namespace,keys:Object.keys(e),locale:i?.locale},"Setting multiple values");for(let[o,a]of Object.entries(e)){if(!(o in this.definition.schema))throw new Error(`Unknown setting key '${o}' in namespace '${this.definition.namespace}'`);let s=this.validators[o];s&&a!==void 0&&s.parse(a)}await this.db.transaction(async o=>{for(let[a,s]of Object.entries(e)){if(s===void 0)continue;let r=this.resolveLocale(a,i);await o.insert(t).values({namespace:this.definition.namespace,scope:this.scope,scopeId:this.scopeId,key:a,locale:r,value:s,updatedAt:new Date}).onConflictDoUpdate({target:[t.namespace,t.scope,t.scopeId,t.key,t.locale],set:{value:s,updatedAt:new Date}})}})}async delete(e,i){let o=this.resolveLocale(e,i);this.logger?.info({namespace:this.definition.namespace,key:e,locale:o},"Deleting setting"),await this.db.delete(t).where(this.whereClause(e,o))}async has(e,i){let o=this.resolveLocale(e,i);return(await this.db.select({key:t.key}).from(t).where(this.whereClause(e,o)).limit(1)).length>0}resolveLocale(e,i){return this.definition.schema[e]?.translatable&&i?.locale?i.locale:f}baseWhere(){return[l(t.namespace,this.definition.namespace),l(t.scope,this.scope),l(t.scopeId,this.scopeId)]}whereClause(e,i=f){return u(...this.baseWhere(),l(t.key,e),l(t.locale,i))}async upsert(e,i,o){await this.db.insert(t).values({namespace:this.definition.namespace,scope:this.scope,scopeId:this.scopeId,key:e,locale:o,value:i,updatedAt:new Date}).onConflictDoUpdate({target:[t.namespace,t.scope,t.scopeId,t.key,t.locale],set:{value:i,updatedAt:new Date}})}};import{getApp as b}from"@murumets-ee/core";function w(n,e){let i=e?.app??b();return new S(n,{db:i.db.readWrite,logger:i.logger.child({settings:n.namespace}),scope:e?.scope,scopeId:e?.scopeId})}function v(n){if(!n.namespace)throw new Error("Settings namespace is required");if(!n.schema||Object.keys(n.schema).length===0)throw new Error("Settings schema must have at least one setting");return n}export{f as DEFAULT_LOCALE,m as GLOBAL_SCOPE_ID,S as SettingsClient,w as createSettingsClient,v as defineSettings,x as setting};
|
package/dist/plugin.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Plugin } from '@murumets-ee/core';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Settings plugin for @murumets-ee/core.
|
|
5
|
-
*
|
|
6
|
-
* Registers the settings Drizzle tables with the schema registry
|
|
7
|
-
* so they can be discovered for migrations and queries.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { defineConfig } from '@murumets-ee/core'
|
|
12
|
-
* import { settings } from '@murumets-ee/settings/plugin'
|
|
13
|
-
*
|
|
14
|
-
* export default defineConfig({
|
|
15
|
-
* plugins: [settings()],
|
|
16
|
-
* })
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
declare function settings(): Plugin;
|
|
21
|
-
|
|
22
|
-
export { settings };
|
package/dist/schema.d.ts
DELETED
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Drizzle schema for settings tables.
|
|
5
|
-
*
|
|
6
|
-
* Two tables:
|
|
7
|
-
* - toolkit_settings: typed key-value settings grouped by namespace and scope
|
|
8
|
-
* - toolkit_view_state: schemaless user-scoped JSON blobs with optional TTL
|
|
9
|
-
*
|
|
10
|
-
* Usage in drizzle.config.ts:
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import type { Config } from 'drizzle-kit'
|
|
13
|
-
* export default {
|
|
14
|
-
* schema: ['./generated/schema.ts', '@murumets-ee/settings/schema'],
|
|
15
|
-
* // ...
|
|
16
|
-
* } satisfies Config
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
/**
|
|
20
|
-
* Typed settings table.
|
|
21
|
-
*
|
|
22
|
-
* Stores key-value pairs grouped by namespace and scoped
|
|
23
|
-
* to global, team, or user contexts.
|
|
24
|
-
*
|
|
25
|
-
* scopeId uses '__global__' sentinel for global scope to avoid
|
|
26
|
-
* PostgreSQL's NULL != NULL behavior in unique constraints.
|
|
27
|
-
*/
|
|
28
|
-
declare const toolkitSettings: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
29
|
-
name: "toolkit_settings";
|
|
30
|
-
schema: undefined;
|
|
31
|
-
columns: {
|
|
32
|
-
id: drizzle_orm_pg_core.PgColumn<{
|
|
33
|
-
name: "id";
|
|
34
|
-
tableName: "toolkit_settings";
|
|
35
|
-
dataType: "string";
|
|
36
|
-
columnType: "PgUUID";
|
|
37
|
-
data: string;
|
|
38
|
-
driverParam: string;
|
|
39
|
-
notNull: true;
|
|
40
|
-
hasDefault: true;
|
|
41
|
-
isPrimaryKey: true;
|
|
42
|
-
isAutoincrement: false;
|
|
43
|
-
hasRuntimeDefault: false;
|
|
44
|
-
enumValues: undefined;
|
|
45
|
-
baseColumn: never;
|
|
46
|
-
identity: undefined;
|
|
47
|
-
generated: undefined;
|
|
48
|
-
}, {}, {}>;
|
|
49
|
-
namespace: drizzle_orm_pg_core.PgColumn<{
|
|
50
|
-
name: "namespace";
|
|
51
|
-
tableName: "toolkit_settings";
|
|
52
|
-
dataType: "string";
|
|
53
|
-
columnType: "PgVarchar";
|
|
54
|
-
data: string;
|
|
55
|
-
driverParam: string;
|
|
56
|
-
notNull: true;
|
|
57
|
-
hasDefault: false;
|
|
58
|
-
isPrimaryKey: false;
|
|
59
|
-
isAutoincrement: false;
|
|
60
|
-
hasRuntimeDefault: false;
|
|
61
|
-
enumValues: [string, ...string[]];
|
|
62
|
-
baseColumn: never;
|
|
63
|
-
identity: undefined;
|
|
64
|
-
generated: undefined;
|
|
65
|
-
}, {}, {
|
|
66
|
-
length: 100;
|
|
67
|
-
}>;
|
|
68
|
-
scope: drizzle_orm_pg_core.PgColumn<{
|
|
69
|
-
name: "scope";
|
|
70
|
-
tableName: "toolkit_settings";
|
|
71
|
-
dataType: "string";
|
|
72
|
-
columnType: "PgVarchar";
|
|
73
|
-
data: string;
|
|
74
|
-
driverParam: string;
|
|
75
|
-
notNull: true;
|
|
76
|
-
hasDefault: true;
|
|
77
|
-
isPrimaryKey: false;
|
|
78
|
-
isAutoincrement: false;
|
|
79
|
-
hasRuntimeDefault: false;
|
|
80
|
-
enumValues: [string, ...string[]];
|
|
81
|
-
baseColumn: never;
|
|
82
|
-
identity: undefined;
|
|
83
|
-
generated: undefined;
|
|
84
|
-
}, {}, {
|
|
85
|
-
length: 20;
|
|
86
|
-
}>;
|
|
87
|
-
scopeId: drizzle_orm_pg_core.PgColumn<{
|
|
88
|
-
name: "scope_id";
|
|
89
|
-
tableName: "toolkit_settings";
|
|
90
|
-
dataType: "string";
|
|
91
|
-
columnType: "PgVarchar";
|
|
92
|
-
data: string;
|
|
93
|
-
driverParam: string;
|
|
94
|
-
notNull: true;
|
|
95
|
-
hasDefault: true;
|
|
96
|
-
isPrimaryKey: false;
|
|
97
|
-
isAutoincrement: false;
|
|
98
|
-
hasRuntimeDefault: false;
|
|
99
|
-
enumValues: [string, ...string[]];
|
|
100
|
-
baseColumn: never;
|
|
101
|
-
identity: undefined;
|
|
102
|
-
generated: undefined;
|
|
103
|
-
}, {}, {
|
|
104
|
-
length: 100;
|
|
105
|
-
}>;
|
|
106
|
-
key: drizzle_orm_pg_core.PgColumn<{
|
|
107
|
-
name: "key";
|
|
108
|
-
tableName: "toolkit_settings";
|
|
109
|
-
dataType: "string";
|
|
110
|
-
columnType: "PgVarchar";
|
|
111
|
-
data: string;
|
|
112
|
-
driverParam: string;
|
|
113
|
-
notNull: true;
|
|
114
|
-
hasDefault: false;
|
|
115
|
-
isPrimaryKey: false;
|
|
116
|
-
isAutoincrement: false;
|
|
117
|
-
hasRuntimeDefault: false;
|
|
118
|
-
enumValues: [string, ...string[]];
|
|
119
|
-
baseColumn: never;
|
|
120
|
-
identity: undefined;
|
|
121
|
-
generated: undefined;
|
|
122
|
-
}, {}, {
|
|
123
|
-
length: 255;
|
|
124
|
-
}>;
|
|
125
|
-
locale: drizzle_orm_pg_core.PgColumn<{
|
|
126
|
-
name: "locale";
|
|
127
|
-
tableName: "toolkit_settings";
|
|
128
|
-
dataType: "string";
|
|
129
|
-
columnType: "PgVarchar";
|
|
130
|
-
data: string;
|
|
131
|
-
driverParam: string;
|
|
132
|
-
notNull: true;
|
|
133
|
-
hasDefault: true;
|
|
134
|
-
isPrimaryKey: false;
|
|
135
|
-
isAutoincrement: false;
|
|
136
|
-
hasRuntimeDefault: false;
|
|
137
|
-
enumValues: [string, ...string[]];
|
|
138
|
-
baseColumn: never;
|
|
139
|
-
identity: undefined;
|
|
140
|
-
generated: undefined;
|
|
141
|
-
}, {}, {
|
|
142
|
-
length: 10;
|
|
143
|
-
}>;
|
|
144
|
-
value: drizzle_orm_pg_core.PgColumn<{
|
|
145
|
-
name: "value";
|
|
146
|
-
tableName: "toolkit_settings";
|
|
147
|
-
dataType: "json";
|
|
148
|
-
columnType: "PgJsonb";
|
|
149
|
-
data: unknown;
|
|
150
|
-
driverParam: unknown;
|
|
151
|
-
notNull: false;
|
|
152
|
-
hasDefault: false;
|
|
153
|
-
isPrimaryKey: false;
|
|
154
|
-
isAutoincrement: false;
|
|
155
|
-
hasRuntimeDefault: false;
|
|
156
|
-
enumValues: undefined;
|
|
157
|
-
baseColumn: never;
|
|
158
|
-
identity: undefined;
|
|
159
|
-
generated: undefined;
|
|
160
|
-
}, {}, {}>;
|
|
161
|
-
updatedAt: drizzle_orm_pg_core.PgColumn<{
|
|
162
|
-
name: "updated_at";
|
|
163
|
-
tableName: "toolkit_settings";
|
|
164
|
-
dataType: "date";
|
|
165
|
-
columnType: "PgTimestamp";
|
|
166
|
-
data: Date;
|
|
167
|
-
driverParam: string;
|
|
168
|
-
notNull: true;
|
|
169
|
-
hasDefault: true;
|
|
170
|
-
isPrimaryKey: false;
|
|
171
|
-
isAutoincrement: false;
|
|
172
|
-
hasRuntimeDefault: false;
|
|
173
|
-
enumValues: undefined;
|
|
174
|
-
baseColumn: never;
|
|
175
|
-
identity: undefined;
|
|
176
|
-
generated: undefined;
|
|
177
|
-
}, {}, {}>;
|
|
178
|
-
updatedBy: drizzle_orm_pg_core.PgColumn<{
|
|
179
|
-
name: "updated_by";
|
|
180
|
-
tableName: "toolkit_settings";
|
|
181
|
-
dataType: "string";
|
|
182
|
-
columnType: "PgUUID";
|
|
183
|
-
data: string;
|
|
184
|
-
driverParam: string;
|
|
185
|
-
notNull: false;
|
|
186
|
-
hasDefault: false;
|
|
187
|
-
isPrimaryKey: false;
|
|
188
|
-
isAutoincrement: false;
|
|
189
|
-
hasRuntimeDefault: false;
|
|
190
|
-
enumValues: undefined;
|
|
191
|
-
baseColumn: never;
|
|
192
|
-
identity: undefined;
|
|
193
|
-
generated: undefined;
|
|
194
|
-
}, {}, {}>;
|
|
195
|
-
};
|
|
196
|
-
dialect: "pg";
|
|
197
|
-
}>;
|
|
198
|
-
/**
|
|
199
|
-
* View state table.
|
|
200
|
-
*
|
|
201
|
-
* Stores schemaless user-scoped JSON blobs for persisting
|
|
202
|
-
* UI state (table filters, column order, etc.) with optional TTL.
|
|
203
|
-
*/
|
|
204
|
-
declare const toolkitViewState: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
205
|
-
name: "toolkit_view_state";
|
|
206
|
-
schema: undefined;
|
|
207
|
-
columns: {
|
|
208
|
-
id: drizzle_orm_pg_core.PgColumn<{
|
|
209
|
-
name: "id";
|
|
210
|
-
tableName: "toolkit_view_state";
|
|
211
|
-
dataType: "string";
|
|
212
|
-
columnType: "PgUUID";
|
|
213
|
-
data: string;
|
|
214
|
-
driverParam: string;
|
|
215
|
-
notNull: true;
|
|
216
|
-
hasDefault: true;
|
|
217
|
-
isPrimaryKey: true;
|
|
218
|
-
isAutoincrement: false;
|
|
219
|
-
hasRuntimeDefault: false;
|
|
220
|
-
enumValues: undefined;
|
|
221
|
-
baseColumn: never;
|
|
222
|
-
identity: undefined;
|
|
223
|
-
generated: undefined;
|
|
224
|
-
}, {}, {}>;
|
|
225
|
-
userId: drizzle_orm_pg_core.PgColumn<{
|
|
226
|
-
name: "user_id";
|
|
227
|
-
tableName: "toolkit_view_state";
|
|
228
|
-
dataType: "string";
|
|
229
|
-
columnType: "PgUUID";
|
|
230
|
-
data: string;
|
|
231
|
-
driverParam: string;
|
|
232
|
-
notNull: true;
|
|
233
|
-
hasDefault: false;
|
|
234
|
-
isPrimaryKey: false;
|
|
235
|
-
isAutoincrement: false;
|
|
236
|
-
hasRuntimeDefault: false;
|
|
237
|
-
enumValues: undefined;
|
|
238
|
-
baseColumn: never;
|
|
239
|
-
identity: undefined;
|
|
240
|
-
generated: undefined;
|
|
241
|
-
}, {}, {}>;
|
|
242
|
-
viewKey: drizzle_orm_pg_core.PgColumn<{
|
|
243
|
-
name: "view_key";
|
|
244
|
-
tableName: "toolkit_view_state";
|
|
245
|
-
dataType: "string";
|
|
246
|
-
columnType: "PgVarchar";
|
|
247
|
-
data: string;
|
|
248
|
-
driverParam: string;
|
|
249
|
-
notNull: true;
|
|
250
|
-
hasDefault: false;
|
|
251
|
-
isPrimaryKey: false;
|
|
252
|
-
isAutoincrement: false;
|
|
253
|
-
hasRuntimeDefault: false;
|
|
254
|
-
enumValues: [string, ...string[]];
|
|
255
|
-
baseColumn: never;
|
|
256
|
-
identity: undefined;
|
|
257
|
-
generated: undefined;
|
|
258
|
-
}, {}, {
|
|
259
|
-
length: 255;
|
|
260
|
-
}>;
|
|
261
|
-
state: drizzle_orm_pg_core.PgColumn<{
|
|
262
|
-
name: "state";
|
|
263
|
-
tableName: "toolkit_view_state";
|
|
264
|
-
dataType: "json";
|
|
265
|
-
columnType: "PgJsonb";
|
|
266
|
-
data: unknown;
|
|
267
|
-
driverParam: unknown;
|
|
268
|
-
notNull: true;
|
|
269
|
-
hasDefault: false;
|
|
270
|
-
isPrimaryKey: false;
|
|
271
|
-
isAutoincrement: false;
|
|
272
|
-
hasRuntimeDefault: false;
|
|
273
|
-
enumValues: undefined;
|
|
274
|
-
baseColumn: never;
|
|
275
|
-
identity: undefined;
|
|
276
|
-
generated: undefined;
|
|
277
|
-
}, {}, {}>;
|
|
278
|
-
expiresAt: drizzle_orm_pg_core.PgColumn<{
|
|
279
|
-
name: "expires_at";
|
|
280
|
-
tableName: "toolkit_view_state";
|
|
281
|
-
dataType: "date";
|
|
282
|
-
columnType: "PgTimestamp";
|
|
283
|
-
data: Date;
|
|
284
|
-
driverParam: string;
|
|
285
|
-
notNull: false;
|
|
286
|
-
hasDefault: false;
|
|
287
|
-
isPrimaryKey: false;
|
|
288
|
-
isAutoincrement: false;
|
|
289
|
-
hasRuntimeDefault: false;
|
|
290
|
-
enumValues: undefined;
|
|
291
|
-
baseColumn: never;
|
|
292
|
-
identity: undefined;
|
|
293
|
-
generated: undefined;
|
|
294
|
-
}, {}, {}>;
|
|
295
|
-
updatedAt: drizzle_orm_pg_core.PgColumn<{
|
|
296
|
-
name: "updated_at";
|
|
297
|
-
tableName: "toolkit_view_state";
|
|
298
|
-
dataType: "date";
|
|
299
|
-
columnType: "PgTimestamp";
|
|
300
|
-
data: Date;
|
|
301
|
-
driverParam: string;
|
|
302
|
-
notNull: true;
|
|
303
|
-
hasDefault: true;
|
|
304
|
-
isPrimaryKey: false;
|
|
305
|
-
isAutoincrement: false;
|
|
306
|
-
hasRuntimeDefault: false;
|
|
307
|
-
enumValues: undefined;
|
|
308
|
-
baseColumn: never;
|
|
309
|
-
identity: undefined;
|
|
310
|
-
generated: undefined;
|
|
311
|
-
}, {}, {}>;
|
|
312
|
-
};
|
|
313
|
-
dialect: "pg";
|
|
314
|
-
}>;
|
|
315
|
-
|
|
316
|
-
export { toolkitSettings, toolkitViewState };
|
package/dist/schema.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b}from"./chunk-E3K4GXDC.js";export{a as toolkitSettings,b as toolkitViewState};
|