@bitakit/core 0.2.0 → 0.2.2

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.
@@ -74,7 +74,7 @@ type AtPath<Path extends string, Value> = Path extends `${infer Head}.${infer Ta
74
74
  } : {
75
75
  readonly [K in Path]: Value;
76
76
  };
77
- /** Dotted names become nested namespaces: `todos.items` is `services.todos.items`. */
77
+ /** Dotted names become nested namespaces: `todos.list` is `services.todos.list`. */
78
78
  export type Namespace<Entries extends object> = keyof Entries extends never ? {} : Intersection<{
79
79
  [K in keyof Entries & string]: AtPath<K, Entries[K]>;
80
80
  }[keyof Entries & string]>;
@@ -11,8 +11,8 @@ export type ServiceEntry = {
11
11
  plugin: string;
12
12
  };
13
13
  /**
14
- * Service names as contributions see them: IDs such as `todos.items` form the tree
15
- * `services.todos.items`; aliases (`exposeAs`, contracts) are extra paths onto the same
14
+ * Service names as contributions see them: IDs such as `todos.list` form the tree
15
+ * `services.todos.list`; aliases (`exposeAs`, contracts) are extra paths onto the same
16
16
  * instance. Resolution never creates instances; the container stays the only owner.
17
17
  */
18
18
  export declare class ServiceNames {
@@ -1,8 +1,8 @@
1
1
  import { BitaKitStartupError } from './startup-error.js';
2
2
  import { BitaKitServiceError } from './app/service-error.js';
3
3
  /**
4
- * Service names as contributions see them: IDs such as `todos.items` form the tree
5
- * `services.todos.items`; aliases (`exposeAs`, contracts) are extra paths onto the same
4
+ * Service names as contributions see them: IDs such as `todos.list` form the tree
5
+ * `services.todos.list`; aliases (`exposeAs`, contracts) are extra paths onto the same
6
6
  * instance. Resolution never creates instances; the container stays the only owner.
7
7
  */
8
8
  export class ServiceNames {
@@ -1,5 +1,5 @@
1
1
  import { defineAction } from '@bitakit/core';
2
2
 
3
3
  export default defineAction({
4
- execute: ({ services }) => services.todos.tasks.list(),
4
+ execute: ({ services }) => services.todos.list.all(),
5
5
  });
@@ -1,5 +1,5 @@
1
1
  import { defineAction } from '@bitakit/core';
2
2
 
3
3
  export default defineAction({
4
- execute: ({ services, input }) => services.todos.tasks.create(input),
4
+ execute: ({ services, input }) => services.todos.list.create(input),
5
5
  });
@@ -1,7 +1,7 @@
1
1
  import { defineAction } from '@bitakit/core';
2
2
 
3
3
  export default defineAction({
4
- // Re-evaluated whenever the tasks store changes: disabled while the list is empty.
5
- enabled: ({ services }) => services.todos.tasks.state.get().items.length > 0,
6
- execute: ({ services, input }) => services.todos.tasks.delete(input),
4
+ // Re-evaluated whenever the list store changes: disabled while the list is empty.
5
+ enabled: ({ services }) => services.todos.list.state.get().todos.length > 0,
6
+ execute: ({ services, input }) => services.todos.list.delete(input),
7
7
  });
@@ -1,13 +1,13 @@
1
1
  import { definePlugin } from '@bitakit/core';
2
- import tasks from './services/tasks.mjs';
2
+ import list from './services/list.mjs';
3
3
  import events from './events.mjs';
4
4
  import create from './actions/create.mjs';
5
- import list from './actions/list.mjs';
5
+ import all from './actions/all.mjs';
6
6
  import remove from './actions/delete.mjs';
7
7
 
8
8
  export default definePlugin({
9
9
  id: 'todos',
10
10
  events,
11
- services: { tasks },
12
- actions: { create, list, delete: remove },
11
+ services: { list },
12
+ actions: { create, all, delete: remove },
13
13
  });
@@ -0,0 +1,24 @@
1
+ import { defineService } from '@bitakit/core';
2
+
3
+ /** The Todos data and behavior: an observable store plus the methods that change it. */
4
+ export default defineService(({ store, events }) => {
5
+ const state = store({ todos: [], nextId: 1 });
6
+
7
+ return {
8
+ state,
9
+ create(title) {
10
+ const todo = { id: state.get().nextId, title, done: false };
11
+ state.set((s) => ({ todos: [...s.todos, todo], nextId: s.nextId + 1 }));
12
+ events.emit('todos.changed', { kind: 'added', id: todo.id });
13
+ return todo;
14
+ },
15
+ all: () => [...state.get().todos],
16
+ delete(id) {
17
+ const before = state.get().todos.length;
18
+ state.set((s) => ({ ...s, todos: s.todos.filter((todo) => todo.id !== id) }));
19
+ const removed = state.get().todos.length < before;
20
+ if (removed) events.emit('todos.changed', { kind: 'removed', id });
21
+ return removed;
22
+ },
23
+ };
24
+ });
@@ -10,9 +10,9 @@ try {
10
10
  await actions.execute('todos.create', 'Learn plugins');
11
11
  await actions.execute('todos.create', 'Connect a service');
12
12
  console.log('Delete enabled after:', actions.get('todos.delete').enabled);
13
- console.log('Before:', (await actions.execute('todos.list')).value);
13
+ console.log('Before:', (await actions.execute('todos.all')).value);
14
14
  await actions.execute('todos.delete', 2);
15
- console.log('After:', (await actions.execute('todos.list')).value);
15
+ console.log('After:', (await actions.execute('todos.all')).value);
16
16
  } finally {
17
17
  await stop();
18
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitakit/core",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -39,7 +39,7 @@
39
39
  "zustand": "^5.0.0"
40
40
  },
41
41
  "peerDependencies": {
42
- "@bitakit/discovery": "^0.2.0",
42
+ "@bitakit/discovery": "^0.2.2",
43
43
  "jiti": "^2.7.0"
44
44
  },
45
45
  "peerDependenciesMeta": {
@@ -51,7 +51,7 @@
51
51
  }
52
52
  },
53
53
  "devDependencies": {
54
- "@bitakit/discovery": "^0.2.0",
54
+ "@bitakit/discovery": "^0.2.2",
55
55
  "jiti": "^2.7.0",
56
56
  "typescript": "^5.9.3"
57
57
  },
@@ -20,7 +20,7 @@ export type MountedPlugin = {
20
20
  app: BitaKitApp;
21
21
  /** The runtime's ActionList; IDs known from `ActionMap` type the input and result of `execute`. */
22
22
  actions: ActionList;
23
- /** Services as the plugin's contributions see them: `services.notes.items`. */
23
+ /** Services as the plugin's contributions see them: `services.notes.list`. */
24
24
  services: Services;
25
25
  /** The runtime bus plus every event emitted while mounted. */
26
26
  events: EventService & { recorded: Pick<BitaKitEvent, 'type' | 'data'>[] };
package/testing/index.mjs CHANGED
@@ -139,7 +139,7 @@ export async function mountPlugin(directory = 'src', options = {}) {
139
139
  runtime,
140
140
  app: runtime.app,
141
141
  actions,
142
- /** Services as the plugin's contributions see them: `services.notes.items`. */
142
+ /** Services as the plugin's contributions see them: `services.notes.list`. */
143
143
  services: runtime.services,
144
144
  events: Object.assign(runtime.events, { recorded }),
145
145
  /** Executes `<plugin>.<name>` (or a full action ID) and returns the execution outcome. */
@@ -1,24 +0,0 @@
1
- import { defineService } from '@bitakit/core';
2
-
3
- /** The Todos data and behavior: an observable store plus the methods that change it. */
4
- export default defineService(({ store, events }) => {
5
- const state = store({ items: [], nextId: 1 });
6
-
7
- return {
8
- state,
9
- create(title) {
10
- const task = { id: state.get().nextId, title, done: false };
11
- state.set((s) => ({ items: [...s.items, task], nextId: s.nextId + 1 }));
12
- events.emit('todos.changed', { kind: 'added', id: task.id });
13
- return task;
14
- },
15
- list: () => [...state.get().items],
16
- delete(id) {
17
- const before = state.get().items.length;
18
- state.set((s) => ({ ...s, items: s.items.filter((task) => task.id !== id) }));
19
- const removed = state.get().items.length < before;
20
- if (removed) events.emit('todos.changed', { kind: 'removed', id });
21
- return removed;
22
- },
23
- };
24
- });