Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/src/state/adapters/default-state-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export class FileStateAdapter implements StateAdapter {

return Object.entries(data)
.map(([key, value]) => {
const [groupId, itemKey] = key.split(':')
const [groupId, ...keyParts] = key.split(':')
const itemKey = keyParts.join(':')
const itemValue = JSON.parse(value)
return { groupId, key: itemKey, value: itemValue, type: inferType(itemValue) }
})
Expand Down
15 changes: 9 additions & 6 deletions packages/core/src/state/adapters/memory-state-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ export class MemoryStateAdapter implements StateAdapter {

async items(input: StateItemsInput): Promise<StateItem[]> {
return Object.entries(this.state)
.map(([key, value]) => ({
groupId: key.split(':')[0],
key: key.split(':')[1],
type: inferType(value),
value: value as StateItem['value'],
}))
.map(([key, value]) => {
const [groupId, ...keyParts] = key.split(':')
return {
groupId,
key: keyParts.join(':'),
type: inferType(value),
value: value as StateItem['value'],
}
})
.filter((item) => (input.groupId ? item.groupId === input.groupId : true))
.filter((item) => (input.filter ? filterItem(item, input.filter) : true))
}
Expand Down
2 changes: 1 addition & 1 deletion playground/motia.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ function localPluginExample(motia: MotiaPluginContext): MotiaPlugin {
}

export default config({
plugins: [statesPlugin, endpointPlugin, logsPlugin, observabilityPlugin, examplePlugin, localPluginExample],
plugins: [observabilityPlugin, statesPlugin, endpointPlugin, logsPlugin, examplePlugin, localPluginExample],
})
3 changes: 2 additions & 1 deletion plugins/plugin-states/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export const api = (motia: MotiaPluginContext): void => {
async (req: ApiRequest, ctx: FlowContext): Promise<ApiResponse> => {
try {
for (const id of (req.body as { ids: string[] }).ids) {
const [groupId, key] = id.split(':')
const [groupId, ...keyParts] = id.split(':')
const key = keyParts.join(':')
await ctx.state.delete(groupId, key)
}

Expand Down
Loading