@pikku/schedule 0.12.6 → 0.12.8

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/CHANGELOG.md CHANGED
@@ -1,3 +1,135 @@
1
+ ## 0.12.8
2
+
3
+ ### Patch Changes
4
+
5
+ - 4c7a1b5: Run the monorepo's own scripts through bun instead of yarn. What moves is the
6
+ package manager each package's `prepublishOnly` and build scripts invoke, plus
7
+ the two manifest fixes bun needs to resolve the tree: `uWebSockets.js` is
8
+ declared with an explicit `github:` specifier, and `@pikku/uws-handler` marks
9
+ its `uWebSockets.js` peer optional so a bun install of a consumer that brings
10
+ its own uWS app does not try to fetch it from the registry.
11
+
12
+ Three published behaviours change, all of them cases where an isolated
13
+ `node_modules` or bun as the runtime had been papered over by yarn's hoisting:
14
+
15
+ - `@pikku/migrator-sql` turns foreign keys on when it opens a sqlite database
16
+ through bun. `node:sqlite` enforces them by default and `bun:sqlite` does not,
17
+ which silently turned every `ON DELETE CASCADE` into a no-op under
18
+ `bunx --bun pikku`.
19
+ - `@pikku/cli` resolves a deploy provider against the project being deployed
20
+ rather than against wherever the CLI itself is installed, which is what its
21
+ own "is not installed" error asks the user to arrange.
22
+ - `@pikku/cli` treats a specifier a runtime hands straight back — bun does this
23
+ for the modules it implements itself — as not resolved from the project, so
24
+ it falls back rather than loading the runtime's own copy.
25
+
26
+ - Updated dependencies [4c7a1b5]
27
+ - @pikku/core@0.12.108
28
+
29
+ ## 0.12.7
30
+
31
+ ### Patch Changes
32
+
33
+ - 266e3bc: One door per name: `@pikku/core/ecosystem/*` and the package root are gone
34
+
35
+ `@pikku/core` published every module twice. `ecosystem/http` re-exported
36
+ `./http`, `ecosystem/services` re-exported `./services`, and a name was
37
+ reachable through either — so every addition had to be made in two places, and a
38
+ consumer's import said nothing about what it actually used. The package root was
39
+ the same problem at a larger scale: a single barrel of 206 names that no bundler
40
+ could take apart, and the one specifier that revealed nothing at all.
41
+
42
+ Both are deleted. Every name now lives on the subpath that owns it, and every
43
+ import carries that subpath — `@pikku/core/http`, `@pikku/core/services`,
44
+ `@pikku/core/errors`, `@pikku/core/types`.
45
+
46
+ Deleting the facades meant the raw subpaths had to become a superset of them,
47
+ which they were not: the facade tree had accumulated 25 names with no raw home
48
+ and about 26 more filed under a different area than the module they came from.
49
+ Those names moved to the area that owns them, and three areas were published as
50
+ new entry points rather than left on a root that is going away — `./types` (the
51
+ shared type surface, the largest single destination), `./state` and
52
+ `./classification`.
53
+
54
+ `./classification` is one door onto one subject: what a value is and how it must
55
+ be handled. Its three halves would each have been an entry point — the brands
56
+ and manifest types, the stored-form helpers (`hashToken`, `unsafeAsSealed` and
57
+ friends), and `SecretValue` — split by whether a name happens to be a type or a
58
+ value, which is the same defect as the facades. The duration and versioned-id
59
+ helpers went to `./utils`, which already published, and `PikkuRequest` went to
60
+ `./function`: it is the transport-agnostic request base, not an HTTP one — HTTP
61
+ has `PikkuHTTPAbstractRequest`, and the only thing outside core that extends
62
+ `PikkuRequest` is Azure's timer request.
63
+
64
+ `./types` inherited the root barrel's habit before it inherited its contents, so
65
+ the names with an owner elsewhere were moved off it. The middleware types and the
66
+ five middleware factories — `pikkuMiddleware`, `pikkuMiddlewareFactory`,
67
+ `pikkuChannelMiddleware`, `pikkuChannelMiddlewareFactory` and
68
+ `pikkuAgentMiddleware`, runtime values on a types entry point — are now
69
+ `@pikku/core/middleware`; the function meta types are `@pikku/core/function`;
70
+ `SerializedError` is `@pikku/core/errors`; and the generic TypeScript helpers
71
+ (`MakeRequired`, `PickRequired`, `PickOptional`, `RequireAtLeastOne`,
72
+ `JSONPrimitive`, `JSONValue`) are `@pikku/core/utils`. What is left on `./types`
73
+ is the vocabulary the wirings share, which no single module owns.
74
+
75
+ `pikku` was itself a root barrel — `export * from '@pikku/core'` — and
76
+ now exports only the services it bundles.
77
+
78
+ One module survives at the old specifier, and only for the bootstrap:
79
+ `packages/cli` is generated by the _published_ CLI pinned in its `build.sh`, and
80
+ that CLI still writes a bare `@pikku/core` into the files it generates for the
81
+ CLI itself. `bootstrap-compat/root.ts` carries the eight types it names, a test
82
+ in core fails if that list grows, and it goes when the pin moves to a CLI
83
+ released from this branch. The adapter names the pinned CLI reaches for —
84
+ `pikkuState` and `CreateWireServices` — are rewritten to `@pikku/core/state` and
85
+ `@pikku/core/types` by the same `build.sh` patch pass, so no second shim is
86
+ needed for them.
87
+
88
+ A guard test keeps the root shut: it parses imports and rejects a bare
89
+ `@pikku/core` rather than grepping for it, because several tests hold a user's
90
+ file as a template literal, where `import … from '@pikku/core'` is fixture text
91
+ rather than an import this repo makes.
92
+
93
+ An agent scaffold a project generated under an older CLI is refreshed rather
94
+ than left to fail: `pikku all` already deleted one importing an entry point
95
+ `@pikku/core` no longer publishes, and the `#pikku` hub joins that list.
96
+ Without it a project that scaffolds the agent endpoint but
97
+ declares no agents keeps the old file forever — the generator that would rewrite
98
+ it only runs when agents exist, and the file being present is what stops it
99
+ being regenerated as missing.
100
+
101
+ `pikku new addon` also wrote a tsconfig `paths` map naming only the deleted hub.
102
+ An addon's `imports` map points into `dist`, so `paths` is what resolves
103
+ `#pikku/<leaf>` for the addon's own source build — it now names the two leaf
104
+ patterns, in both the addon and its test harness.
105
+
106
+ - 786dae5: Bump every dependency whose latest release is a major across the monorepo, and
107
+ port the code the majors broke: `cookie` 2's `parseCookie`/`stringifySetCookie`
108
+ API in `@pikku/core` and the three runtime HTTP adapters, and assistant-ui 0.15's
109
+ store client in `@pikku/assistant-ui`.
110
+ - 6eef0a0: Bump every dependency to its latest compatible minor/patch across the monorepo.
111
+ - Updated dependencies [7722ceb]
112
+ - Updated dependencies [375c1ff]
113
+ - Updated dependencies [02a70cd]
114
+ - Updated dependencies [aeef159]
115
+ - Updated dependencies [a281de6]
116
+ - Updated dependencies [266e3bc]
117
+ - Updated dependencies [02a70cd]
118
+ - Updated dependencies [786dae5]
119
+ - Updated dependencies [6eef0a0]
120
+ - Updated dependencies [3561d67]
121
+ - Updated dependencies [a91c433]
122
+ - Updated dependencies [02a70cd]
123
+ - Updated dependencies [9537f74]
124
+ - Updated dependencies [2b57ca8]
125
+ - Updated dependencies [266e3bc]
126
+ - Updated dependencies [9fce0f1]
127
+ - Updated dependencies [83683a0]
128
+ - Updated dependencies [456c88b]
129
+ - Updated dependencies [456c88b]
130
+ - Updated dependencies [c127273]
131
+ - @pikku/core@0.12.85
132
+
1
133
  ## 0.12.6
2
134
 
3
135
  ### Patch Changes
@@ -1,6 +1,6 @@
1
- import type { CoreUserSession } from '@pikku/core';
2
- import type { ScheduledTaskInfo, ScheduledTaskSummary } from '@pikku/core/ecosystem/services';
3
- import { SchedulerService } from '@pikku/core';
1
+ import type { CoreUserSession } from '@pikku/core/types';
2
+ import type { ScheduledTaskInfo, ScheduledTaskSummary } from '@pikku/core/services';
3
+ import { SchedulerService } from '@pikku/core/services';
4
4
  /**
5
5
  * In-memory SchedulerService implementation.
6
6
  * Uses CronJob for recurring tasks and setTimeout for delayed RPCs.
@@ -1,9 +1,9 @@
1
1
  import { CronJob } from 'cron';
2
- import { SchedulerService } from '@pikku/core';
3
- import { parseDurationString } from '@pikku/core/ecosystem/types';
4
- import { pikkuState, getSingletonServices } from '@pikku/core/ecosystem';
2
+ import { SchedulerService } from '@pikku/core/services';
3
+ import { parseDurationString } from '@pikku/core/utils';
4
+ import { pikkuState, getSingletonServices } from '@pikku/core/state';
5
5
  import { runScheduledTask } from '@pikku/core/scheduler';
6
- import { getScheduledTasks } from '@pikku/core/ecosystem/scheduler';
6
+ import { getScheduledTasks } from '@pikku/core/scheduler';
7
7
  import { rpcService } from '@pikku/core/rpc';
8
8
  const getLogger = () => {
9
9
  return pikkuState(null, 'package', 'singletonServices').logger;
package/package.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "@pikku/schedule",
3
- "version": "0.12.6",
3
+ "version": "0.12.8",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/pikkujs/pikku.git",
7
+ "directory": "packages/schedule"
8
+ },
4
9
  "description": "In-memory scheduler service for Pikku cron wirings",
5
10
  "author": "yasser.fadl@gmail.com",
6
11
  "license": "MIT",
@@ -16,21 +21,20 @@
16
21
  "test": "bash run-tests.sh",
17
22
  "test:watch": "bash run-tests.sh --watch",
18
23
  "test:coverage": "bash run-tests.sh --coverage",
19
- "prepublishOnly": "yarn build"
24
+ "prepublishOnly": "bun run build"
20
25
  },
21
26
  "peerDependencies": {
22
- "@pikku/core": "^0.12.84"
27
+ "@pikku/core": "^0.12.108"
23
28
  },
24
29
  "devDependencies": {
25
- "@types/node": "^24.11.0",
26
- "typescript": "^6.0.3"
30
+ "@types/node": "^24.13.3"
27
31
  },
28
32
  "engines": {
29
33
  "node": ">=24"
30
34
  },
31
35
  "dependencies": {
32
36
  "cron": "^4.4.0",
33
- "cron-schedule": "^5.0.4"
37
+ "cron-schedule": "^6.0.0"
34
38
  },
35
39
  "exports": {
36
40
  ".": {
package/run-tests.sh CHANGED
@@ -34,20 +34,35 @@ files=($(find src -type f -name "*.test.ts"))
34
34
  # Check if any files matched the pattern
35
35
  if [ ${#files[@]} -eq 0 ]; then
36
36
  echo "No test files found matching pattern: $pattern"
37
+ if [ "${STRICT_TEST_DISCOVERY}" = "1" ]; then
38
+ exit 1
39
+ fi
37
40
  exit 0
38
41
  fi
39
42
 
40
- # Construct the node command
41
- node_cmd=(node --import tsx --test)
43
+ # Construct the bun command
44
+ #
45
+ # --parallel gives every test file its own worker process, which is what node's
46
+ # `--test` did. Several suites keep module-level caches (a TypeScript program, a
47
+ # temp fixture directory) that a shared process would leak between files.
48
+ #
49
+ # --timeout because bun caps a test at 5s by default where node had no cap, and
50
+ # the suites that build real TypeScript programs run well past that.
51
+ bun_cmd=(bun test --parallel --timeout 120000)
42
52
 
43
53
  # Append options based on flags
44
54
  if [ "$watch_mode" = true ]; then
45
- node_cmd+=(--watch)
55
+ # --watch reruns in one process; parallel workers have nothing to watch.
56
+ bun_cmd=(bun test --watch --timeout 120000)
46
57
  fi
47
58
 
48
59
  if [ "$coverage_mode" = true ]; then
49
- node_cmd+=(--test-coverage-include="src/**/*.{ts,js}" --test-coverage-exclude="**/dist/**" --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info)
60
+ # --coverage-dir=. keeps lcov.info at the package root: CI merges every
61
+ # package's report by prefixing its SF paths with the file's own directory,
62
+ # so a nested coverage/ directory would re-root them one level too deep.
63
+ bun_cmd+=(--coverage --coverage-reporter=lcov --coverage-reporter=text --coverage-dir=.)
64
+ export PIKKU_TEST_COVERAGE=1
50
65
  fi
51
66
 
52
- # Execute the node command with the expanded list of files
53
- "${node_cmd[@]}" "${files[@]}"
67
+ # Execute the bun command with the expanded list of files
68
+ "${bun_cmd[@]}" "${files[@]}"
@@ -1,94 +0,0 @@
1
- import { describe, test } from 'node:test'
2
- import assert from 'node:assert/strict'
3
- import { pikkuState } from '@pikku/core/ecosystem'
4
- import { addFunction } from '@pikku/core/function'
5
-
6
- import { InMemorySchedulerService } from './in-memory-scheduler-service.js'
7
-
8
- const waitFor = async (predicate: () => boolean, withinMs = 2000) => {
9
- const deadline = Date.now() + withinMs
10
- while (Date.now() < deadline) {
11
- if (predicate()) return true
12
- await new Promise((resolve) => setTimeout(resolve, 10))
13
- }
14
- return false
15
- }
16
-
17
- describe('InMemorySchedulerService scheduleRPC', () => {
18
- test('schedules and executes delayed RPC', async () => {
19
- const logger = {
20
- info: () => {},
21
- warn: () => {},
22
- debug: () => {},
23
- error: () => {},
24
- }
25
-
26
- pikkuState(null, 'package', 'singletonServices', {
27
- logger,
28
- } as any)
29
-
30
- const scheduler = new InMemorySchedulerService()
31
- try {
32
- const taskId = await scheduler.scheduleRPC(50, 'testRpc', { ok: true }, {
33
- userId: 'user-1',
34
- } as any)
35
- assert.ok(taskId)
36
-
37
- const task = await scheduler.getTask(taskId)
38
- assert.ok(task)
39
- assert.equal(task.rpcName, 'testRpc')
40
- } finally {
41
- await scheduler.close()
42
- }
43
- })
44
-
45
- /**
46
- * The delay actually has to invoke the RPC, with its data.
47
- *
48
- * The test above only proved the task was registered, which is why the
49
- * scheduler could dispatch through `runScheduledTask` — a lookup against the
50
- * *cron task* registry that no scheduled RPC is ever in — and still pass.
51
- * Every internally scheduled RPC failed with ScheduledTaskNotFoundError,
52
- * `pikkuWorkflowSleeper` among them, so an async workflow never woke from
53
- * `workflow.sleep`.
54
- */
55
- test('invokes the named RPC with its data once the delay elapses', async () => {
56
- const errors: string[] = []
57
- const logger = {
58
- info: () => {},
59
- warn: () => {},
60
- debug: () => {},
61
- error: (message: string) => errors.push(message),
62
- }
63
- pikkuState(null, 'package', 'singletonServices', { logger } as any)
64
-
65
- const calls: unknown[] = []
66
- addFunction(
67
- 'delayedTestRpc',
68
- {
69
- func: async (_services: any, data: unknown) => calls.push(data),
70
- } as any,
71
- null
72
- )
73
- pikkuState(null, 'function', 'meta')['delayedTestRpc'] = {
74
- name: 'delayedTestRpc',
75
- sessionless: true,
76
- permissions: [],
77
- } as any
78
-
79
- const scheduler = new InMemorySchedulerService()
80
- try {
81
- await scheduler.scheduleRPC(20, 'delayedTestRpc', {
82
- runId: 'run-1',
83
- stepId: 'step-1',
84
- })
85
- assert.ok(
86
- await waitFor(() => calls.length > 0),
87
- `RPC was never invoked; scheduler errors: ${JSON.stringify(errors)}`
88
- )
89
- assert.deepEqual(calls[0], { runId: 'run-1', stepId: 'step-1' })
90
- } finally {
91
- await scheduler.close()
92
- }
93
- })
94
- })
@@ -1,166 +0,0 @@
1
- import { CronJob } from 'cron'
2
- import type { CoreUserSession } from '@pikku/core'
3
- import type {
4
- ScheduledTaskInfo,
5
- ScheduledTaskSummary,
6
- } from '@pikku/core/ecosystem/services'
7
- import { SchedulerService } from '@pikku/core'
8
- import { parseDurationString } from '@pikku/core/ecosystem/types'
9
- import { pikkuState, getSingletonServices } from '@pikku/core/ecosystem'
10
- import { runScheduledTask } from '@pikku/core/scheduler'
11
- import { getScheduledTasks } from '@pikku/core/ecosystem/scheduler'
12
- import { rpcService } from '@pikku/core/rpc'
13
-
14
- interface DelayedTask {
15
- taskId: string
16
- rpcName: string
17
- data?: any
18
- session?: CoreUserSession
19
- scheduledFor: Date
20
- timer: ReturnType<typeof setTimeout>
21
- }
22
-
23
- const getLogger = () => {
24
- return pikkuState(null, 'package', 'singletonServices')!.logger
25
- }
26
-
27
- /**
28
- * In-memory SchedulerService implementation.
29
- * Uses CronJob for recurring tasks and setTimeout for delayed RPCs.
30
- */
31
- export class InMemorySchedulerService extends SchedulerService {
32
- private cronJobs = new Map<string, CronJob>()
33
- private delayedTasks = new Map<string, DelayedTask>()
34
- private idCounter = 0
35
-
36
- async init(): Promise<void> {}
37
-
38
- /**
39
- * Schedule a one-off delayed RPC call via setTimeout
40
- */
41
- async scheduleRPC(
42
- delay: number | string,
43
- rpcName: string,
44
- data?: any,
45
- session?: CoreUserSession
46
- ): Promise<string> {
47
- const delayMs =
48
- typeof delay === 'string' ? parseDurationString(delay) : delay
49
- const taskId = `inmem-${++this.idCounter}-${Date.now()}`
50
- const scheduledFor = new Date(Date.now() + delayMs)
51
-
52
- const timer = setTimeout(async () => {
53
- this.delayedTasks.delete(taskId)
54
- try {
55
- // An RPC, not a cron task. `runScheduledTask` looks the name up in the
56
- // scheduler's task registry, which only ever holds wired cron tasks —
57
- // so every internally-scheduled RPC died here as
58
- // ScheduledTaskNotFoundError. The one that matters most is
59
- // `pikkuWorkflowSleeper`: it is registered by the workflow service as a
60
- // function, and it is what wakes a run from `workflow.sleep`. With the
61
- // wake-up lost to a swallowed log line, an async workflow run stopped
62
- // at its first sleep and stayed `running` forever.
63
- //
64
- // `data` has to be forwarded for the same reason. The sleeper is called
65
- // with `{ runId, stepId }` and cannot identify the sleeping step
66
- // without it — it was captured in `delayedTasks` but never passed on.
67
- // This matches what the BullMQ and pg-boss schedulers already do:
68
- // enqueue `{ rpcName, data, session }` and invoke the RPC with it.
69
- const services = getSingletonServices()
70
- const rpc = rpcService.getContextRPCService(
71
- services as any,
72
- {},
73
- false
74
- ) as { invoke: (name: string, data: unknown) => Promise<unknown> }
75
- await rpc.invoke(rpcName, data)
76
- } catch (err: unknown) {
77
- getLogger().error(`Failed to execute delayed RPC '${rpcName}': ${err}`)
78
- }
79
- }, delayMs)
80
-
81
- this.delayedTasks.set(taskId, {
82
- taskId,
83
- rpcName,
84
- data,
85
- session,
86
- scheduledFor,
87
- timer,
88
- })
89
-
90
- return taskId
91
- }
92
-
93
- async unschedule(taskId: string): Promise<boolean> {
94
- const task = this.delayedTasks.get(taskId)
95
- if (task) {
96
- clearTimeout(task.timer)
97
- this.delayedTasks.delete(taskId)
98
- return true
99
- }
100
- return false
101
- }
102
-
103
- async getTask(taskId: string): Promise<ScheduledTaskInfo | null> {
104
- const task = this.delayedTasks.get(taskId)
105
- if (!task) return null
106
- return {
107
- taskId: task.taskId,
108
- rpcName: task.rpcName,
109
- scheduledFor: task.scheduledFor,
110
- data: task.data,
111
- session: task.session,
112
- status: 'scheduled',
113
- }
114
- }
115
-
116
- async getAllTasks(): Promise<ScheduledTaskSummary[]> {
117
- return Array.from(this.delayedTasks.values()).map((t) => ({
118
- taskId: t.taskId,
119
- rpcName: t.rpcName,
120
- scheduledFor: t.scheduledFor,
121
- }))
122
- }
123
-
124
- async close(): Promise<void> {
125
- await this.stop()
126
- // Clear delayed tasks
127
- for (const [, task] of this.delayedTasks) {
128
- clearTimeout(task.timer)
129
- }
130
- this.delayedTasks.clear()
131
- }
132
-
133
- /**
134
- * Start recurring scheduled tasks.
135
- */
136
- async start(): Promise<void> {
137
- const scheduledTasks = getScheduledTasks()
138
- for (const [, task] of scheduledTasks) {
139
- this.startCronJob(task.name, task.schedule)
140
- }
141
- }
142
-
143
- /**
144
- * Stop all recurring CronJobs.
145
- */
146
- async stop(): Promise<void> {
147
- for (const [, job] of this.cronJobs) {
148
- job.stop()
149
- }
150
- this.cronJobs.clear()
151
- }
152
-
153
- private startCronJob(name: string, schedule: string) {
154
- const job = new CronJob(
155
- schedule,
156
- async () => {
157
- getLogger().info(`Running scheduled task: ${name}`)
158
- await runScheduledTask({ name })
159
- getLogger().debug(`Completed scheduled task: ${name}`)
160
- },
161
- null,
162
- true
163
- )
164
- this.cronJobs.set(name, job)
165
- }
166
- }
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- export { InMemorySchedulerService } from './in-memory-scheduler-service.js'
2
-
3
- /**
4
- * @deprecated Use InMemorySchedulerService instead
5
- */
6
- export { InMemorySchedulerService as PikkuTaskScheduler } from './in-memory-scheduler-service.js'
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "extends": "../tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "module": "Node18",
6
- "outDir": "dist",
7
- "target": "esnext",
8
- "declaration": true,
9
- "resolveJsonModule": true
10
- },
11
- "include": ["bin/**/*.ts", "src/**/*.ts"],
12
- "exclude": ["**/*.test.ts", "node_modules", "bin/dist"],
13
- "references": [
14
- {
15
- "path": "../core/tsconfig.json"
16
- }
17
- ]
18
- }
@@ -1 +0,0 @@
1
- {"root":["./src/in-memory-scheduler-service.ts","./src/index.ts"],"version":"6.0.3"}