@coffer-org/plugin-transit 1.4.0 → 1.5.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/dist/bus_route/index.d.ts +1 -1
- package/dist/bus_route/index.js +4 -4
- package/dist/index.js +4 -4
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +13 -12
- package/dist/runtime/sync.d.ts +1 -2
- package/dist/runtime/sync.js +6 -31
- package/dist/schema.js +57 -25
- package/package.json +4 -4
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("@coffer-org/sdk/
|
|
1
|
+
declare const _default: import("@coffer-org/sdk/shelf").ShelfDef;
|
|
2
2
|
export default _default;
|
package/dist/bus_route/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineShelf } from '@coffer-org/sdk/shelf';
|
|
2
2
|
import { field } from '@coffer-org/sdk/fields';
|
|
3
|
-
export default
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export default defineShelf({
|
|
4
|
+
shelf: 'bus_route',
|
|
5
|
+
library: 'transit',
|
|
6
6
|
label: 'transit.bus_route.label',
|
|
7
7
|
icon: 'lucide:bus',
|
|
8
8
|
views: {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineLibrary } from '@coffer-org/sdk/library';
|
|
2
2
|
import { definePlugin } from '@coffer-org/sdk/plugin';
|
|
3
3
|
import { field } from '@coffer-org/sdk/fields';
|
|
4
4
|
import { defineSettings } from '@coffer-org/sdk/settings';
|
|
@@ -7,10 +7,10 @@ export default definePlugin({
|
|
|
7
7
|
id: 'transit',
|
|
8
8
|
version: '1.0.0',
|
|
9
9
|
dependsOn: [],
|
|
10
|
-
|
|
10
|
+
libraries: [
|
|
11
11
|
{
|
|
12
|
-
meta:
|
|
13
|
-
|
|
12
|
+
meta: defineLibrary({ id: 'transit', label: 'transit.library.label', icon: 'lucide:bus', agent: 'Local bus routes and their departure schedules (bus_route).' }),
|
|
13
|
+
shelves: [bus_route],
|
|
14
14
|
},
|
|
15
15
|
],
|
|
16
16
|
settings: defineSettings({
|
package/dist/runtime/index.d.ts
CHANGED
package/dist/runtime/index.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
export { startSync, stopSync } from "./sync.js";
|
|
1
|
+
import { runOnce } from "./sync.js";
|
|
2
|
+
export { runOnce } from "./sync.js";
|
|
3
|
+
const SYNC_INTERVAL_MS = Number(process.env['TRANSIT_SYNC_INTERVAL_MS']) || 6 * 60 * 60 * 1000;
|
|
5
4
|
export const serverHooks = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
backgroundTasks: [
|
|
6
|
+
{
|
|
7
|
+
name: 'transit-sync',
|
|
8
|
+
intervalMs: SYNC_INTERVAL_MS,
|
|
9
|
+
run: async () => {
|
|
10
|
+
await runOnce();
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
],
|
|
12
14
|
agent: {
|
|
13
|
-
instructions: '
|
|
14
|
-
'weekday_times/saturday_times/sunday_times — departure schedule.' +
|
|
15
|
+
instructions: 'bus_route: weekday_times/saturday_times/sunday_times — departure schedule.' +
|
|
15
16
|
' When the schedule changes, update *_times via update_record.',
|
|
16
17
|
},
|
|
17
18
|
};
|
package/dist/runtime/sync.d.ts
CHANGED
|
@@ -12,5 +12,4 @@ export interface BusRouteRecord {
|
|
|
12
12
|
notes: string | null;
|
|
13
13
|
}
|
|
14
14
|
export declare function buildBusEvents(records: BusRouteRecord[]): IcsFile[];
|
|
15
|
-
export declare function
|
|
16
|
-
export declare function stopSync(): void;
|
|
15
|
+
export declare function runOnce(): Promise<void>;
|
package/dist/runtime/sync.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getEm } from '@coffer-org/server/db';
|
|
2
2
|
import { getPluginSettings } from '@coffer-org/server/plugin-runtime';
|
|
3
|
-
import {
|
|
3
|
+
import { syncIcs, buildVEvent, buildRRule } from '@coffer-org/dav';
|
|
4
4
|
import { getLogger } from '@coffer-org/sdk/logger';
|
|
5
5
|
const log = getLogger('transit');
|
|
6
6
|
const REF_DATE = { weekday: '20240101', saturday: '20240106', sunday: '20240107' };
|
|
@@ -55,7 +55,7 @@ export function buildBusEvents(records) {
|
|
|
55
55
|
}
|
|
56
56
|
return files;
|
|
57
57
|
}
|
|
58
|
-
async function runOnce() {
|
|
58
|
+
export async function runOnce() {
|
|
59
59
|
const fork = getEm().fork();
|
|
60
60
|
const rows = (await fork.find('transit__bus_route', {}));
|
|
61
61
|
const icsFiles = buildBusEvents(rows);
|
|
@@ -63,34 +63,9 @@ async function runOnce() {
|
|
|
63
63
|
const calendar = pluginSettings['caldav_calendar'];
|
|
64
64
|
if (!calendar)
|
|
65
65
|
throw new Error('[transit-sync] caldav_calendar is required but not set');
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
collectionUrl: settings.collectionUrl,
|
|
71
|
-
username: settings.principal,
|
|
72
|
-
password: settings.password,
|
|
73
|
-
});
|
|
74
|
-
const coll = new CalDavCollection(ops);
|
|
75
|
-
const result = await coll.syncEvents('bus-route-', icsFiles);
|
|
66
|
+
const result = await syncIcs(calendar, {
|
|
67
|
+
principal: pluginSettings['caldav_username'],
|
|
68
|
+
password: pluginSettings['caldav_password'],
|
|
69
|
+
}, 'bus-route-', icsFiles);
|
|
76
70
|
log.debug(`synced: ${result.written.length} written, ${result.deleted.length} deleted, ${result.failed.length} failed`);
|
|
77
71
|
}
|
|
78
|
-
const INTERVAL_MS = Number(process.env['TRANSIT_SYNC_INTERVAL_MS'] ?? 0) || 6 * 60 * 60 * 1000;
|
|
79
|
-
let timer;
|
|
80
|
-
export async function startSync() {
|
|
81
|
-
try {
|
|
82
|
-
await runOnce();
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
log.error(`initial sync failed: ${e.message}`);
|
|
86
|
-
}
|
|
87
|
-
timer = setInterval(() => {
|
|
88
|
-
void runOnce().catch((e) => log.error(`sync error: ${e.message}`));
|
|
89
|
-
}, INTERVAL_MS);
|
|
90
|
-
}
|
|
91
|
-
export function stopSync() {
|
|
92
|
-
if (timer !== undefined) {
|
|
93
|
-
clearInterval(timer);
|
|
94
|
-
timer = undefined;
|
|
95
|
-
}
|
|
96
|
-
}
|
package/dist/schema.js
CHANGED
|
@@ -21,8 +21,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
//#endregion
|
|
24
|
-
//#region ../sdk/src/
|
|
25
|
-
function
|
|
24
|
+
//#region ../sdk/src/library.ts
|
|
25
|
+
function defineLibrary(v) {
|
|
26
26
|
return v;
|
|
27
27
|
}
|
|
28
28
|
//#endregion
|
|
@@ -154,7 +154,10 @@ function assignProp(target, prop, value) {
|
|
|
154
154
|
}
|
|
155
155
|
function mergeDefs(...defs) {
|
|
156
156
|
const mergedDescriptors = {};
|
|
157
|
-
for (const def of defs)
|
|
157
|
+
for (const def of defs) {
|
|
158
|
+
const descriptors = Object.getOwnPropertyDescriptors(def);
|
|
159
|
+
Object.assign(mergedDescriptors, descriptors);
|
|
160
|
+
}
|
|
158
161
|
return Object.defineProperties({}, mergedDescriptors);
|
|
159
162
|
}
|
|
160
163
|
function esc(str) {
|
|
@@ -476,7 +479,7 @@ var _parse = (_Err) => (schema, value, _ctx, _params) => {
|
|
|
476
479
|
}, ctx);
|
|
477
480
|
if (result instanceof Promise) throw new $ZodAsyncError();
|
|
478
481
|
if (result.issues.length) {
|
|
479
|
-
const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
482
|
+
const e = new ((_params?.Err) ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
480
483
|
captureStackTrace(e, _params?.callee);
|
|
481
484
|
throw e;
|
|
482
485
|
}
|
|
@@ -493,7 +496,7 @@ var _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
|
|
|
493
496
|
}, ctx);
|
|
494
497
|
if (result instanceof Promise) result = await result;
|
|
495
498
|
if (result.issues.length) {
|
|
496
|
-
const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
499
|
+
const e = new ((params?.Err) ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
497
500
|
captureStackTrace(e, params?.callee);
|
|
498
501
|
throw e;
|
|
499
502
|
}
|
|
@@ -1945,7 +1948,7 @@ var $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def) => {
|
|
|
1945
1948
|
inst._zod.optin = "optional";
|
|
1946
1949
|
inst._zod.optout = "optional";
|
|
1947
1950
|
defineLazy(inst._zod, "values", () => {
|
|
1948
|
-
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, void 0]) : void 0;
|
|
1951
|
+
return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, void 0]) : void 0;
|
|
1949
1952
|
});
|
|
1950
1953
|
defineLazy(inst._zod, "pattern", () => {
|
|
1951
1954
|
const pattern = def.innerType._zod.pattern;
|
|
@@ -1979,7 +1982,7 @@ var $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def) => {
|
|
|
1979
1982
|
return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
|
|
1980
1983
|
});
|
|
1981
1984
|
defineLazy(inst._zod, "values", () => {
|
|
1982
|
-
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : void 0;
|
|
1985
|
+
return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, null]) : void 0;
|
|
1983
1986
|
});
|
|
1984
1987
|
inst._zod.parse = (payload, ctx) => {
|
|
1985
1988
|
if (payload.value === null) return payload;
|
|
@@ -4587,7 +4590,7 @@ function password(raw) {
|
|
|
4587
4590
|
* Internal API-token list — keyValue-shaped collection (name + write-only
|
|
4588
4591
|
* token + timestamps), custom renderer (`kind:'internalApiToken'`, own
|
|
4589
4592
|
* create/revoke UI — same trick as url()/perWeekday()). "Internal" = not a
|
|
4590
|
-
* general-purpose field type for plugin
|
|
4593
|
+
* general-purpose field type for plugin shelves, only for the core account
|
|
4591
4594
|
* settings page. `token` is `kind:'password'` so maskSecrets/preserveTree
|
|
4592
4595
|
* already mask/preserve it for free.
|
|
4593
4596
|
*/
|
|
@@ -4686,7 +4689,7 @@ var TEL_RE = /^\+?[\d\s()-]{4,}$/;
|
|
|
4686
4689
|
/** Loose URL: будь-який scheme:// АБО host-з-крапкою (+опц. порт/шлях). Без пробілів. */
|
|
4687
4690
|
var LINK_RE = /^([a-z][a-z0-9+.-]*:\/\/\S+|[\w-]+(\.[\w-]+)+(:\d+)?(\/\S*)?)$/i;
|
|
4688
4691
|
/** CSS named colors (CSS Color Module L4) — для f.colorname. */
|
|
4689
|
-
var CSS_COLOR_NAMES = new Set([
|
|
4692
|
+
var CSS_COLOR_NAMES = /* @__PURE__ */ new Set([
|
|
4690
4693
|
"aliceblue",
|
|
4691
4694
|
"antiquewhite",
|
|
4692
4695
|
"aqua",
|
|
@@ -5147,7 +5150,7 @@ var require_data = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5147
5150
|
},
|
|
5148
5151
|
cs: {
|
|
5149
5152
|
name: "Czech",
|
|
5150
|
-
nativeName: "
|
|
5153
|
+
nativeName: "čeština"
|
|
5151
5154
|
},
|
|
5152
5155
|
cu: {
|
|
5153
5156
|
name: "Old Church Slavonic",
|
|
@@ -5611,7 +5614,7 @@ var require_data = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5611
5614
|
},
|
|
5612
5615
|
sk: {
|
|
5613
5616
|
name: "Slovak",
|
|
5614
|
-
nativeName: "
|
|
5617
|
+
nativeName: "slovenčtina"
|
|
5615
5618
|
},
|
|
5616
5619
|
sl: {
|
|
5617
5620
|
name: "Slovenian",
|
|
@@ -5992,6 +5995,34 @@ function wrapKey(opts, meta) {
|
|
|
5992
5995
|
noEditControl: true
|
|
5993
5996
|
}
|
|
5994
5997
|
};
|
|
5998
|
+
if (opts.emphasis) m = {
|
|
5999
|
+
...m,
|
|
6000
|
+
hints: {
|
|
6001
|
+
...m.hints,
|
|
6002
|
+
emphasis: opts.emphasis
|
|
6003
|
+
}
|
|
6004
|
+
};
|
|
6005
|
+
if (opts.noLabel) m = {
|
|
6006
|
+
...m,
|
|
6007
|
+
hints: {
|
|
6008
|
+
...m.hints,
|
|
6009
|
+
noLabel: true
|
|
6010
|
+
}
|
|
6011
|
+
};
|
|
6012
|
+
if (opts.role) m = {
|
|
6013
|
+
...m,
|
|
6014
|
+
hints: {
|
|
6015
|
+
...m.hints,
|
|
6016
|
+
role: opts.role
|
|
6017
|
+
}
|
|
6018
|
+
};
|
|
6019
|
+
if (opts.pinned) m = {
|
|
6020
|
+
...m,
|
|
6021
|
+
hints: {
|
|
6022
|
+
...m.hints,
|
|
6023
|
+
pinned: true
|
|
6024
|
+
}
|
|
6025
|
+
};
|
|
5995
6026
|
if (opts.default !== void 0) m = {
|
|
5996
6027
|
...m,
|
|
5997
6028
|
default: opts.default
|
|
@@ -6355,8 +6386,8 @@ function relation(raw) {
|
|
|
6355
6386
|
displayKey: o.displayKey ?? "name"
|
|
6356
6387
|
},
|
|
6357
6388
|
relation: {
|
|
6358
|
-
|
|
6359
|
-
type: raw.options.
|
|
6389
|
+
library: raw.options.library,
|
|
6390
|
+
type: raw.options.shelf
|
|
6360
6391
|
},
|
|
6361
6392
|
...multi && { json: true },
|
|
6362
6393
|
zod: optionalize(s, required)
|
|
@@ -7681,7 +7712,7 @@ var createDefaultQueryTester = function(query, options) {
|
|
|
7681
7712
|
};
|
|
7682
7713
|
createDefaultQueryTester.createEqualsOperation;
|
|
7683
7714
|
//#endregion
|
|
7684
|
-
//#region ../sdk/src/
|
|
7715
|
+
//#region ../sdk/src/shelf.ts
|
|
7685
7716
|
/** Flat [storageKey, FieldMeta] pairs of the parent table's columns.
|
|
7686
7717
|
* layout group → flattened; embedded group → prefix `key__`; collection → skipped. */
|
|
7687
7718
|
function fieldEntries(items) {
|
|
@@ -7694,11 +7725,11 @@ function fieldEntries(items) {
|
|
|
7694
7725
|
}
|
|
7695
7726
|
return out;
|
|
7696
7727
|
}
|
|
7697
|
-
function
|
|
7728
|
+
function defineShelf(m) {
|
|
7698
7729
|
const keys = fieldEntries(m.fields).map(([k]) => k);
|
|
7699
7730
|
const dup = keys.find((k, i) => keys.indexOf(k) !== i);
|
|
7700
|
-
if (dup) throw new Error(`[
|
|
7701
|
-
if (m.standalone !== false && !m.views?.table?.length) console.warn(`[
|
|
7731
|
+
if (dup) throw new Error(`[shelf] ${m.library}/${m.shelf}: duplicate key '${dup}'`);
|
|
7732
|
+
if (m.standalone !== false && !m.views?.table?.length) console.warn(`[shelf] ${m.library}/${m.shelf}: standalone shelf without an explicit views.table`);
|
|
7702
7733
|
return m;
|
|
7703
7734
|
}
|
|
7704
7735
|
//#endregion
|
|
@@ -7709,9 +7740,9 @@ function defineModule(m) {
|
|
|
7709
7740
|
* 48 Кишинів→Чореску, 48 Чореску→Кишинів.
|
|
7710
7741
|
* Час відправлень зберігається як JSON-масиви рядків "HH:MM".
|
|
7711
7742
|
*/
|
|
7712
|
-
var bus_route_default =
|
|
7713
|
-
|
|
7714
|
-
|
|
7743
|
+
var bus_route_default = defineShelf({
|
|
7744
|
+
shelf: "bus_route",
|
|
7745
|
+
library: "transit",
|
|
7715
7746
|
label: "transit.bus_route.label",
|
|
7716
7747
|
icon: "lucide:bus",
|
|
7717
7748
|
views: { table: [
|
|
@@ -7775,13 +7806,14 @@ var src_default = definePlugin({
|
|
|
7775
7806
|
id: "transit",
|
|
7776
7807
|
version: "1.0.0",
|
|
7777
7808
|
dependsOn: [],
|
|
7778
|
-
|
|
7779
|
-
meta:
|
|
7809
|
+
libraries: [{
|
|
7810
|
+
meta: defineLibrary({
|
|
7780
7811
|
id: "transit",
|
|
7781
|
-
label: "transit.
|
|
7782
|
-
icon: "lucide:bus"
|
|
7812
|
+
label: "transit.library.label",
|
|
7813
|
+
icon: "lucide:bus",
|
|
7814
|
+
agent: "Local bus routes and their departure schedules (bus_route)."
|
|
7783
7815
|
}),
|
|
7784
|
-
|
|
7816
|
+
shelves: [bus_route_default]
|
|
7785
7817
|
}],
|
|
7786
7818
|
settings: defineSettings({
|
|
7787
7819
|
label: "transit.settings.label",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coffer-org/plugin-transit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24"
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"test": "node --import tsx/esm --test 'src/runtime/*.test.ts'"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@coffer-org/sdk": "^1.
|
|
29
|
-
"@coffer-org/server": "^1.
|
|
30
|
-
"@coffer-org/dav": "^1.
|
|
28
|
+
"@coffer-org/sdk": "^1.5.0",
|
|
29
|
+
"@coffer-org/server": "^1.8.0",
|
|
30
|
+
"@coffer-org/dav": "^1.5.0"
|
|
31
31
|
},
|
|
32
32
|
"coffer": {
|
|
33
33
|
"schema": "dist/schema.js"
|