atom.io 0.46.21 → 0.46.23

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.
@@ -1,6 +1,6 @@
1
- //#region rolldown:runtime
1
+ //#region \0rolldown/runtime.js
2
2
  var __defProp = Object.defineProperty;
3
- var __exportAll = (all, symbols) => {
3
+ var __exportAll = (all, no_symbols) => {
4
4
  let target = {};
5
5
  for (var name in all) {
6
6
  __defProp(target, name, {
@@ -8,7 +8,7 @@ var __exportAll = (all, symbols) => {
8
8
  enumerable: true
9
9
  });
10
10
  }
11
- if (symbols) {
11
+ if (!no_symbols) {
12
12
  __defProp(target, Symbol.toStringTag, { value: "Module" });
13
13
  }
14
14
  return target;
@@ -1,4 +1,4 @@
1
- import { t as __exportAll } from "../chunk-BN_g-Awi.js";
1
+ import { t as __exportAll } from "../chunk-BYypO7fO.js";
2
2
  import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
3
3
 
4
4
  //#region src/eslint-plugin/rules/exact-catch-types.ts
@@ -297,8 +297,7 @@ const plugin = { rules: {
297
297
  "exact-catch-types": exactCatchTypes,
298
298
  "explicit-state-types": explicitStateTypes
299
299
  } };
300
- var eslint_plugin_default = plugin;
301
300
 
302
301
  //#endregion
303
- export { rules_exports as Rules, eslint_plugin_default as default };
302
+ export { rules_exports as Rules, plugin as default };
304
303
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["createRule","Rules.namingConvention","Rules.exactCatchTypes","Rules.explicitStateTypes"],"sources":["../../src/eslint-plugin/rules/exact-catch-types.ts","../../src/eslint-plugin/rules/explicit-state-types.ts","../../src/eslint-plugin/rules/naming-convention.ts","../../src/eslint-plugin/rules/index.ts","../../src/eslint-plugin/index.ts"],"sourcesContent":["import type { TSESTree } from \"@typescript-eslint/utils\"\nimport { AST_NODE_TYPES, ESLintUtils } from \"@typescript-eslint/utils\"\nimport type {\n\tInterfaceType,\n\tSymbol as TsSymbol,\n\tType,\n\tTypeNode,\n} from \"typescript\"\n\nconst createRule = ESLintUtils.RuleCreator(\n\t(name) => `https://atom.io.fyi/docs/eslint-plugin#${name}`,\n)\n\nconst STATE_FUNCTIONS_WITH_CATCH = [\n\t`atom`,\n\t`atomFamily`,\n\t`selector`,\n\t`selectorFamily`,\n]\nconst FAMILY_FUNCTIONS = [`atomFamily`, `selectorFamily`]\n\nexport const exactCatchTypes: ESLintUtils.RuleModule<\n\t`extraneousErrorTypes` | `invalidCatchProperty` | `missingCatchProperty`,\n\t[],\n\tunknown,\n\tESLintUtils.RuleListener\n> = createRule({\n\tname: `catch-constructor-type`,\n\tmeta: {\n\t\ttype: `problem`,\n\t\tdocs: {\n\t\t\tdescription: `Ensures that when an error type (E) is provided to an atom, the 'catch' property is set and all constructors in it are assignable to E.`,\n\t\t},\n\t\tmessages: {\n\t\t\tmissingCatchProperty:\n\t\t\t\t`This {{functionName}} was provided the error type \\`{{errorTypeName}}\\` ` +\n\t\t\t\t`but the required 'catch' property is missing from its options. ` +\n\t\t\t\t`Either remove \\`{{errorTypeName}}\\`, or add \\`catch: [{{errorTypeName}}]\\` to the options object.`,\n\t\t\tinvalidCatchProperty:\n\t\t\t\t`This {{functionName}} was provided a catch array containing the class \\`{{constructorName}}\\`. ` +\n\t\t\t\t`However, that class is not represented in the {{functionName}}'s error type, \\`{{errorTypeName}}\\`. ` +\n\t\t\t\t`As a result, it might catch errors that the {{functionName}} is not designed to handle. ` +\n\t\t\t\t`Either include \\`{{constructorName}}\\` in the {{functionName}}'s error type, or remove it from the 'catch' array.`,\n\t\t\textraneousErrorTypes:\n\t\t\t\t`This {{functionName}} was provided an error type including the class \\`{{errorTypeName}}\\`, ` +\n\t\t\t\t`but its 'catch' property doesn't include a constructor for that class. ` +\n\t\t\t\t`Either include a constructor for \\`{{errorTypeName}}\\` in the 'catch' array, or remove \\`{{errorTypeName}}\\` as a possible error type.`,\n\t\t},\n\t\tschema: [],\n\t},\n\tdefaultOptions: [],\n\tcreate(context) {\n\t\tconst parserServices = ESLintUtils.getParserServices(context)\n\t\tconst checker = parserServices.program.getTypeChecker()\n\n\t\treturn {\n\t\t\tCallExpression(node) {\n\t\t\t\tconst {\n\t\t\t\t\tcallee,\n\t\t\t\t\ttypeArguments: directTypeArguments,\n\t\t\t\t\targuments: callArguments,\n\t\t\t\t} = node\n\n\t\t\t\tlet errorParamIndex = 1\n\n\t\t\t\t// Check if the function call is one of the targeted state functions\n\t\t\t\tlet functionName: string | null = null\n\t\t\t\tif (callee.type === AST_NODE_TYPES.Identifier) {\n\t\t\t\t\tif (STATE_FUNCTIONS_WITH_CATCH.includes(callee.name)) {\n\t\t\t\t\t\tfunctionName = callee.name\n\t\t\t\t\t}\n\t\t\t\t} else if (callee.type === AST_NODE_TYPES.MemberExpression) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tcallee.property.type === AST_NODE_TYPES.Identifier &&\n\t\t\t\t\t\tSTATE_FUNCTIONS_WITH_CATCH.includes(callee.property.name)\n\t\t\t\t\t) {\n\t\t\t\t\t\tfunctionName = callee.property.name\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!functionName) return\n\n\t\t\t\t// Where do the type arguments come from?\n\t\t\t\tlet typeArguments: TSESTree.TSTypeParameterInstantiation | undefined\n\t\t\t\tif (directTypeArguments) {\n\t\t\t\t\ttypeArguments = directTypeArguments\n\t\t\t\t} else {\n\t\t\t\t\tconst parent = node.parent\n\t\t\t\t\tif (\n\t\t\t\t\t\tparent?.type === AST_NODE_TYPES.VariableDeclarator &&\n\t\t\t\t\t\tparent.init === node\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Check if the VariableDeclarator has an id with a TypeAnnotation\n\t\t\t\t\t\tconst declaratorId = parent.id\n\t\t\t\t\t\tif (declaratorId.type === AST_NODE_TYPES.Identifier) {\n\t\t\t\t\t\t\t// Check for 'const myAtom: AtomToken<string> = ...'\n\t\t\t\t\t\t\tconst typeAnnotation = declaratorId.typeAnnotation?.typeAnnotation\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\ttypeAnnotation &&\n\t\t\t\t\t\t\t\t`typeArguments` in typeAnnotation &&\n\t\t\t\t\t\t\t\ttypeAnnotation.typeArguments\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\ttypeArguments = typeAnnotation.typeArguments\n\t\t\t\t\t\t\t\terrorParamIndex = 2 // AtomToken<T, K, E>\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst optionsObject = callArguments[0]\n\n\t\t\t\tif (optionsObject?.type !== AST_NODE_TYPES.ObjectExpression) return\n\n\t\t\t\tconst isFamilyDeclaration = FAMILY_FUNCTIONS.includes(functionName)\n\t\t\t\tif (isFamilyDeclaration) {\n\t\t\t\t\terrorParamIndex = 2 // atomFamily<T, K, E>\n\t\t\t\t}\n\n\t\t\t\tconst errorTypeNode = typeArguments\n\t\t\t\t\t? typeArguments.params[errorParamIndex]\n\t\t\t\t\t: undefined\n\t\t\t\tif (!errorTypeNode) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tlet catchProperty: TSESTree.Property | undefined\n\t\t\t\toptionsObject.properties.forEach((property) => {\n\t\t\t\t\tif (property.type === AST_NODE_TYPES.Property) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t(property.key.type === AST_NODE_TYPES.Identifier &&\n\t\t\t\t\t\t\t\tproperty.key.name === `catch`) ||\n\t\t\t\t\t\t\t(property.key.type === AST_NODE_TYPES.Literal &&\n\t\t\t\t\t\t\t\tproperty.key.value === `catch`)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcatchProperty = property\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})\n\n\t\t\t\tconst typeNode = parserServices.esTreeNodeToTSNodeMap.get(\n\t\t\t\t\terrorTypeNode,\n\t\t\t\t) as TypeNode\n\t\t\t\t// Get the TypeScript Type object for E\n\t\t\t\tconst errorTypeTs = checker.getTypeFromTypeNode(typeNode)\n\t\t\t\tconst errorTypeName = checker.typeToString(errorTypeTs)\n\n\t\t\t\tif (!catchProperty) {\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tnode: optionsObject,\n\t\t\t\t\t\tmessageId: `missingCatchProperty`,\n\t\t\t\t\t\tdata: { functionName, errorTypeName },\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// --- New Validation: Check Constructor Types ---\n\t\t\t\tconst catchArray = catchProperty.value\n\t\t\t\tif (catchArray.type !== AST_NODE_TYPES.ArrayExpression) {\n\t\t\t\t\t// We only check array literals (e.g., [Ctor1, Ctor2])\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// 3. Collect all acceptable nominal symbols from E\n\t\t\t\tconst acceptableErrorSymbols: TsSymbol[] = []\n\n\t\t\t\t// Check if E is a Union Type\n\t\t\t\tif (errorTypeTs.isUnion()) {\n\t\t\t\t\t// Add the symbol of every member of the union (e.g., Symbol(SpecialError), Symbol(FancyError))\n\t\t\t\t\tfor (const memberType of errorTypeTs.types) {\n\t\t\t\t\t\tconst symbol = memberType.getSymbol()\n\t\t\t\t\t\tif (symbol) {\n\t\t\t\t\t\t\tacceptableErrorSymbols.push(symbol)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// E is a single type, add its symbol\n\t\t\t\t\tconst symbol = errorTypeTs.getSymbol()\n\t\t\t\t\tif (symbol) {\n\t\t\t\t\t\tacceptableErrorSymbols.push(symbol)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (catchArray.elements.length === 0) {\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tnode: catchProperty,\n\t\t\t\t\t\tmessageId: `missingCatchProperty`,\n\t\t\t\t\t\tdata: { functionName, errorTypeName },\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst errorSymbolsToRepresent = new Set(acceptableErrorSymbols)\n\n\t\t\t\t// Iterate over each constructor reference in the 'catch' array\n\t\t\t\tfor (const element of catchArray.elements) {\n\t\t\t\t\tif (element?.type !== AST_NODE_TYPES.Identifier) {\n\t\t\t\t\t\t// Only check simple identifier references (e.g., [ClientError])\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\t// Get the type of the constructor identifier (e.g., the Type of 'Error')\n\t\t\t\t\tconst constructorTsNode =\n\t\t\t\t\t\tparserServices.esTreeNodeToTSNodeMap.get(element)\n\t\t\t\t\tconst constructorType = checker.getTypeAtLocation(constructorTsNode)\n\t\t\t\t\tconst constructorName = element.name\n\n\t\t\t\t\t// console.log(`constructorName`, constructorName)\n\n\t\t\t\t\t// Extract the instance type from the constructor type.\n\t\t\t\t\t// e.g., turn 'typeof ClientError' into 'ClientError'\n\t\t\t\t\tlet instanceType: Type | undefined\n\t\t\t\t\tif (\n\t\t\t\t\t\t(constructorType as InterfaceType).getConstructSignatures().length >\n\t\t\t\t\t\t0\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Get the return type of the constructor signature\n\t\t\t\t\t\tconst signature = (\n\t\t\t\t\t\t\tconstructorType as InterfaceType\n\t\t\t\t\t\t).getConstructSignatures()[0]\n\t\t\t\t\t\tinstanceType = signature.getReturnType()\n\t\t\t\t\t}\n\n\t\t\t\t\t// If we couldn't get the instance type, skip the check\n\n\t\t\t\t\tconst constructorInstanceSymbol = instanceType?.getSymbol()\n\t\t\t\t\tif (!constructorInstanceSymbol) continue\n\n\t\t\t\t\t// Check for symbol identity\n\t\t\t\t\tif (acceptableErrorSymbols.includes(constructorInstanceSymbol)) {\n\t\t\t\t\t\terrorSymbolsToRepresent.delete(constructorInstanceSymbol)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\tnode: element,\n\t\t\t\t\t\t\tmessageId: `invalidCatchProperty`,\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tfunctionName,\n\t\t\t\t\t\t\t\tconstructorName: constructorName,\n\t\t\t\t\t\t\t\terrorTypeName: errorTypeName,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfor (const errorSymbol of errorSymbolsToRepresent) {\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tnode: catchProperty,\n\t\t\t\t\t\tmessageId: `extraneousErrorTypes`,\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\terrorTypeName: checker.symbolToString(errorSymbol),\n\t\t\t\t\t\t\tfunctionName,\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\t},\n})\n","/* eslint-disable @typescript-eslint/switch-exhaustiveness-check */\nimport { AST_NODE_TYPES, ESLintUtils } from \"@typescript-eslint/utils\"\n\nconst createRule = ESLintUtils.RuleCreator(\n\t(name) => `https://atom.io.fyi/docs/eslint-plugin#${name}`,\n)\n\nconst STATE_FUNCTIONS = [\n\t`atom`,\n\t`atomFamily`,\n\t`mutableAtom`,\n\t`mutableAtomFamily`,\n\t`selector`,\n\t`selectorFamily`,\n]\n\ntype Options = [\n\t{\n\t\tpermitAnnotation?: boolean\n\t},\n]\n\nexport const explicitStateTypes: ESLintUtils.RuleModule<\n\t`noTypeArgument` | `noTypeArgumentOrAnnotation`,\n\tOptions,\n\tunknown,\n\tESLintUtils.RuleListener\n> = createRule({\n\tname: `explicit-state-types`,\n\tmeta: {\n\t\ttype: `problem`,\n\t\tdocs: {\n\t\t\tdescription: `State declarations must have generic type arguments directly passed to them`,\n\t\t},\n\t\tmessages: {\n\t\t\tnoTypeArgument: `State declarations must have generic type arguments directly passed to them.`,\n\t\t\tnoTypeArgumentOrAnnotation: `State declarations must have generic type arguments directly passed to them, or a top-level type annotation.`,\n\t\t},\n\t\tschema: [\n\t\t\t{\n\t\t\t\ttype: `object`,\n\t\t\t\tproperties: {\n\t\t\t\t\tpermitAnnotation: {\n\t\t\t\t\t\ttype: `boolean`,\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tadditionalProperties: false,\n\t\t\t},\n\t\t],\n\t},\n\tdefaultOptions: [\n\t\t{\n\t\t\tpermitAnnotation: false,\n\t\t},\n\t],\n\tcreate(context) {\n\t\tconst options = context.options[0]\n\t\tconst permitAnnotation = options?.permitAnnotation ?? false\n\n\t\treturn {\n\t\t\tCallExpression(node) {\n\t\t\t\tconst callee = node.callee\n\n\t\t\t\tswitch (callee.type) {\n\t\t\t\t\tcase `Identifier`:\n\t\t\t\t\t\tif (STATE_FUNCTIONS.includes(callee.name) === false) {\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase `MemberExpression`:\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t(callee.property.type === `Identifier` &&\n\t\t\t\t\t\t\t\tSTATE_FUNCTIONS.includes(callee.property.name)) === false\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// Check for the *required* generic type argument first\n\t\t\t\tif (node.typeArguments) {\n\t\t\t\t\treturn // Generic type argument is present, no error\n\t\t\t\t}\n\n\t\t\t\t// If generic arguments are missing, check if the top-level annotation exception is enabled AND present\n\t\t\t\tif (permitAnnotation) {\n\t\t\t\t\tlet hasAnnotation = false\n\t\t\t\t\t// Check if the CallExpression is the initializer of a variable declarator\n\t\t\t\t\tconst parent = node.parent\n\t\t\t\t\tif (\n\t\t\t\t\t\tparent?.type === AST_NODE_TYPES.VariableDeclarator &&\n\t\t\t\t\t\tparent.init === node\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Check if the VariableDeclarator has an id with a TypeAnnotation\n\t\t\t\t\t\tconst declaratorId = parent.id\n\t\t\t\t\t\tif (declaratorId.type === AST_NODE_TYPES.Identifier) {\n\t\t\t\t\t\t\t// Check for 'const myAtom: AtomToken<string> = ...'\n\t\t\t\t\t\t\thasAnnotation = Boolean(declaratorId.typeAnnotation)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (hasAnnotation) {\n\t\t\t\t\t\treturn // Exception met: type annotation is on the variable declaration\n\t\t\t\t\t}\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tnode,\n\t\t\t\t\t\tmessageId: `noTypeArgumentOrAnnotation`,\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tcontext.report({\n\t\t\t\t\tnode,\n\t\t\t\t\tmessageId: `noTypeArgument`,\n\t\t\t\t})\n\t\t\t},\n\t\t}\n\t},\n})\n","import type { RuleType } from \"@eslint/core\"\nimport type { Rule } from \"eslint\"\nimport type * as ESTree from \"estree\"\n\nconst SUFFIX_DICTIONARY = {\n\tatom: `Atom`,\n\tatomFamily: `Atoms`,\n\tmutableAtom: `Atom`,\n\tmutableAtomFamily: `Atoms`,\n\tselector: `Selector`,\n\tselectorFamily: `Selectors`,\n} as const\n\nconst PLURAL_DICTIONARY = {\n\tatom: `atoms`,\n\tatomFamily: `atom families`,\n\tmutableAtom: `atoms`,\n\tmutableAtomFamily: `atom families`,\n\tselector: `selectors`,\n\tselectorFamily: `selector families`,\n}\n\ntype StateFunctionName = keyof typeof SUFFIX_DICTIONARY\n\nexport const namingConvention: {\n\tmeta: {\n\t\ttype: RuleType\n\t\tdocs: {\n\t\t\tdescription: string\n\t\t\tcategory: string\n\t\t\trecommended: boolean\n\t\t\turl: string\n\t\t}\n\t\tfixable: `code`\n\t\tschema: never[]\n\t}\n\tcreate(context: Rule.RuleContext): Rule.NodeListener\n} = {\n\tmeta: {\n\t\ttype: `problem`,\n\t\tdocs: {\n\t\t\tdescription: `The variable names given to atoms, selectors, and their respective families should match their given key property, and should follow a consistent format`,\n\t\t\tcategory: `Best Practices`,\n\t\t\trecommended: false,\n\t\t\turl: ``,\n\t\t},\n\t\tfixable: `code`,\n\t\tschema: [],\n\t},\n\n\tcreate(context) {\n\t\treturn {\n\t\t\tCallExpression(node) {\n\t\t\t\t// atom(...)\n\t\t\t\tif (\n\t\t\t\t\tnode.callee.type !== `Identifier` &&\n\t\t\t\t\tnode.callee.type !== `MemberExpression`\n\t\t\t\t) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\t// Must be assigned: const x = atom(...)\n\t\t\t\tif (node.parent?.type !== `VariableDeclarator`) return\n\t\t\t\tif (node.parent.init !== node) return\n\t\t\t\tif (node.parent.id.type !== `Identifier`) return\n\n\t\t\t\tlet calleeName: StateFunctionName\n\n\t\t\t\tswitch (node.callee.type) {\n\t\t\t\t\tcase `Identifier`:\n\t\t\t\t\t\tcalleeName = node.callee.name as StateFunctionName\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase `MemberExpression`:\n\t\t\t\t\t\tif (node.callee.property.type !== `Identifier`) return\n\t\t\t\t\t\tcalleeName = node.callee.property.name as StateFunctionName\n\t\t\t\t\t\tbreak\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tswitch (calleeName) {\n\t\t\t\t\tcase `atom`:\n\t\t\t\t\tcase `atomFamily`:\n\t\t\t\t\tcase `mutableAtom`:\n\t\t\t\t\tcase `mutableAtomFamily`:\n\t\t\t\t\tcase `selector`:\n\t\t\t\t\tcase `selectorFamily`:\n\t\t\t\t\t\tbreak // ^ targets of this rule\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst suffix = SUFFIX_DICTIONARY[calleeName]\n\t\t\t\tconst plural = PLURAL_DICTIONARY[calleeName]\n\n\t\t\t\tconst variableName = node.parent.id.name\n\n\t\t\t\t// Enforce FooAtom naming\n\t\t\t\tif (!variableName.endsWith(suffix)) {\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tnode: node.parent.id,\n\t\t\t\t\t\tmessage: `Names of ${plural} should end with '${suffix}'.`,\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst expectedKey = variableName.slice(0, -suffix.length)\n\n\t\t\t\t// Must have first argument object\n\t\t\t\tconst arg = node.arguments[0]\n\t\t\t\tif (arg?.type !== `ObjectExpression`) return\n\n\t\t\t\t// Find key property\n\t\t\t\tconst keyProp = arg.properties.find(\n\t\t\t\t\t(prop): prop is ESTree.Property =>\n\t\t\t\t\t\tprop.type === `Property` &&\n\t\t\t\t\t\t((prop.key.type === `Identifier` && prop.key.name === `key`) ||\n\t\t\t\t\t\t\t(prop.key.type === `Literal` && prop.key.value === `key`)),\n\t\t\t\t)\n\n\t\t\t\tif (!keyProp) return\n\n\t\t\t\t// Must be string literal or template literal\n\t\t\t\tif (\n\t\t\t\t\tkeyProp.value.type !== `Literal` ||\n\t\t\t\t\ttypeof keyProp.value.value !== `string`\n\t\t\t\t) {\n\t\t\t\t\tif (keyProp.value.type !== `TemplateLiteral`) return\n\t\t\t\t}\n\n\t\t\t\tconst actualKey =\n\t\t\t\t\tkeyProp.value.type === `Literal`\n\t\t\t\t\t\t? keyProp.value.value\n\t\t\t\t\t\t: keyProp.value.quasis[0].value.raw\n\n\t\t\t\tif (\n\t\t\t\t\tactualKey !== expectedKey ||\n\t\t\t\t\t(`quasis` in keyProp.value && keyProp.value.quasis.length > 1)\n\t\t\t\t) {\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tnode: keyProp.value,\n\t\t\t\t\t\tmessage: `Keys of ${plural} should be consistent with the names of their variables.`,\n\t\t\t\t\t\tfix(fixer) {\n\t\t\t\t\t\t\treturn fixer.replaceText(\n\t\t\t\t\t\t\t\tkeyProp.value,\n\t\t\t\t\t\t\t\tJSON.stringify(expectedKey),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\t},\n} satisfies Rule.RuleModule\n","export * from \"./exact-catch-types\"\nexport * from \"./explicit-state-types\"\nexport * from \"./naming-convention\"\n","import type { ESLint } from \"eslint\"\n\nimport * as Rules from \"./rules\"\n\nexport { Rules }\n\nconst plugin: ESLint.Plugin = {\n\trules: {\n\t\t\"naming-convention\": Rules.namingConvention as any,\n\t\t\"exact-catch-types\": Rules.exactCatchTypes as any,\n\t\t\"explicit-state-types\": Rules.explicitStateTypes as any,\n\t},\n} satisfies ESLint.Plugin\n\nexport default plugin\n"],"mappings":";;;;AASA,MAAMA,eAAa,YAAY,aAC7B,SAAS,0CAA0C,OACpD;AAED,MAAM,6BAA6B;CAClC;CACA;CACA;CACA;CACA;AACD,MAAM,mBAAmB,CAAC,cAAc,iBAAiB;AAEzD,MAAa,kBAKTA,aAAW;CACd,MAAM;CACN,MAAM;EACL,MAAM;EACN,MAAM,EACL,aAAa,2IACb;EACD,UAAU;GACT,sBACC;GAGD,sBACC;GAID,sBACC;GAGD;EACD,QAAQ,EAAE;EACV;CACD,gBAAgB,EAAE;CAClB,OAAO,SAAS;EACf,MAAM,iBAAiB,YAAY,kBAAkB,QAAQ;EAC7D,MAAM,UAAU,eAAe,QAAQ,gBAAgB;AAEvD,SAAO,EACN,eAAe,MAAM;GACpB,MAAM,EACL,QACA,eAAe,qBACf,WAAW,kBACR;GAEJ,IAAI,kBAAkB;GAGtB,IAAI,eAA8B;AAClC,OAAI,OAAO,SAAS,eAAe,YAClC;QAAI,2BAA2B,SAAS,OAAO,KAAK,CACnD,gBAAe,OAAO;cAEb,OAAO,SAAS,eAAe,kBACzC;QACC,OAAO,SAAS,SAAS,eAAe,cACxC,2BAA2B,SAAS,OAAO,SAAS,KAAK,CAEzD,gBAAe,OAAO,SAAS;;AAIjC,OAAI,CAAC,aAAc;GAGnB,IAAI;AACJ,OAAI,oBACH,iBAAgB;QACV;IACN,MAAM,SAAS,KAAK;AACpB,QACC,QAAQ,SAAS,eAAe,sBAChC,OAAO,SAAS,MACf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
+ {"version":3,"file":"index.js","names":["createRule","Rules.namingConvention","Rules.exactCatchTypes","Rules.explicitStateTypes"],"sources":["../../src/eslint-plugin/rules/exact-catch-types.ts","../../src/eslint-plugin/rules/explicit-state-types.ts","../../src/eslint-plugin/rules/naming-convention.ts","../../src/eslint-plugin/rules/index.ts","../../src/eslint-plugin/index.ts"],"sourcesContent":["import type { TSESTree } from \"@typescript-eslint/utils\"\nimport { AST_NODE_TYPES, ESLintUtils } from \"@typescript-eslint/utils\"\nimport type {\n\tInterfaceType,\n\tSymbol as TsSymbol,\n\tType,\n\tTypeNode,\n} from \"typescript\"\n\nconst createRule = ESLintUtils.RuleCreator(\n\t(name) => `https://atom.io.fyi/docs/eslint-plugin#${name}`,\n)\n\nconst STATE_FUNCTIONS_WITH_CATCH = [\n\t`atom`,\n\t`atomFamily`,\n\t`selector`,\n\t`selectorFamily`,\n]\nconst FAMILY_FUNCTIONS = [`atomFamily`, `selectorFamily`]\n\nexport const exactCatchTypes: ESLintUtils.RuleModule<\n\t`extraneousErrorTypes` | `invalidCatchProperty` | `missingCatchProperty`,\n\t[],\n\tunknown,\n\tESLintUtils.RuleListener\n> = createRule({\n\tname: `catch-constructor-type`,\n\tmeta: {\n\t\ttype: `problem`,\n\t\tdocs: {\n\t\t\tdescription: `Ensures that when an error type (E) is provided to an atom, the 'catch' property is set and all constructors in it are assignable to E.`,\n\t\t},\n\t\tmessages: {\n\t\t\tmissingCatchProperty:\n\t\t\t\t`This {{functionName}} was provided the error type \\`{{errorTypeName}}\\` ` +\n\t\t\t\t`but the required 'catch' property is missing from its options. ` +\n\t\t\t\t`Either remove \\`{{errorTypeName}}\\`, or add \\`catch: [{{errorTypeName}}]\\` to the options object.`,\n\t\t\tinvalidCatchProperty:\n\t\t\t\t`This {{functionName}} was provided a catch array containing the class \\`{{constructorName}}\\`. ` +\n\t\t\t\t`However, that class is not represented in the {{functionName}}'s error type, \\`{{errorTypeName}}\\`. ` +\n\t\t\t\t`As a result, it might catch errors that the {{functionName}} is not designed to handle. ` +\n\t\t\t\t`Either include \\`{{constructorName}}\\` in the {{functionName}}'s error type, or remove it from the 'catch' array.`,\n\t\t\textraneousErrorTypes:\n\t\t\t\t`This {{functionName}} was provided an error type including the class \\`{{errorTypeName}}\\`, ` +\n\t\t\t\t`but its 'catch' property doesn't include a constructor for that class. ` +\n\t\t\t\t`Either include a constructor for \\`{{errorTypeName}}\\` in the 'catch' array, or remove \\`{{errorTypeName}}\\` as a possible error type.`,\n\t\t},\n\t\tschema: [],\n\t},\n\tdefaultOptions: [],\n\tcreate(context) {\n\t\tconst parserServices = ESLintUtils.getParserServices(context)\n\t\tconst checker = parserServices.program.getTypeChecker()\n\n\t\treturn {\n\t\t\tCallExpression(node) {\n\t\t\t\tconst {\n\t\t\t\t\tcallee,\n\t\t\t\t\ttypeArguments: directTypeArguments,\n\t\t\t\t\targuments: callArguments,\n\t\t\t\t} = node\n\n\t\t\t\tlet errorParamIndex = 1\n\n\t\t\t\t// Check if the function call is one of the targeted state functions\n\t\t\t\tlet functionName: string | null = null\n\t\t\t\tif (callee.type === AST_NODE_TYPES.Identifier) {\n\t\t\t\t\tif (STATE_FUNCTIONS_WITH_CATCH.includes(callee.name)) {\n\t\t\t\t\t\tfunctionName = callee.name\n\t\t\t\t\t}\n\t\t\t\t} else if (callee.type === AST_NODE_TYPES.MemberExpression) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tcallee.property.type === AST_NODE_TYPES.Identifier &&\n\t\t\t\t\t\tSTATE_FUNCTIONS_WITH_CATCH.includes(callee.property.name)\n\t\t\t\t\t) {\n\t\t\t\t\t\tfunctionName = callee.property.name\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!functionName) return\n\n\t\t\t\t// Where do the type arguments come from?\n\t\t\t\tlet typeArguments: TSESTree.TSTypeParameterInstantiation | undefined\n\t\t\t\tif (directTypeArguments) {\n\t\t\t\t\ttypeArguments = directTypeArguments\n\t\t\t\t} else {\n\t\t\t\t\tconst parent = node.parent\n\t\t\t\t\tif (\n\t\t\t\t\t\tparent?.type === AST_NODE_TYPES.VariableDeclarator &&\n\t\t\t\t\t\tparent.init === node\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Check if the VariableDeclarator has an id with a TypeAnnotation\n\t\t\t\t\t\tconst declaratorId = parent.id\n\t\t\t\t\t\tif (declaratorId.type === AST_NODE_TYPES.Identifier) {\n\t\t\t\t\t\t\t// Check for 'const myAtom: AtomToken<string> = ...'\n\t\t\t\t\t\t\tconst typeAnnotation = declaratorId.typeAnnotation?.typeAnnotation\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\ttypeAnnotation &&\n\t\t\t\t\t\t\t\t`typeArguments` in typeAnnotation &&\n\t\t\t\t\t\t\t\ttypeAnnotation.typeArguments\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\ttypeArguments = typeAnnotation.typeArguments\n\t\t\t\t\t\t\t\terrorParamIndex = 2 // AtomToken<T, K, E>\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst optionsObject = callArguments[0]\n\n\t\t\t\tif (optionsObject?.type !== AST_NODE_TYPES.ObjectExpression) return\n\n\t\t\t\tconst isFamilyDeclaration = FAMILY_FUNCTIONS.includes(functionName)\n\t\t\t\tif (isFamilyDeclaration) {\n\t\t\t\t\terrorParamIndex = 2 // atomFamily<T, K, E>\n\t\t\t\t}\n\n\t\t\t\tconst errorTypeNode = typeArguments\n\t\t\t\t\t? typeArguments.params[errorParamIndex]\n\t\t\t\t\t: undefined\n\t\t\t\tif (!errorTypeNode) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tlet catchProperty: TSESTree.Property | undefined\n\t\t\t\toptionsObject.properties.forEach((property) => {\n\t\t\t\t\tif (property.type === AST_NODE_TYPES.Property) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t(property.key.type === AST_NODE_TYPES.Identifier &&\n\t\t\t\t\t\t\t\tproperty.key.name === `catch`) ||\n\t\t\t\t\t\t\t(property.key.type === AST_NODE_TYPES.Literal &&\n\t\t\t\t\t\t\t\tproperty.key.value === `catch`)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcatchProperty = property\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})\n\n\t\t\t\tconst typeNode = parserServices.esTreeNodeToTSNodeMap.get(\n\t\t\t\t\terrorTypeNode,\n\t\t\t\t) as TypeNode\n\t\t\t\t// Get the TypeScript Type object for E\n\t\t\t\tconst errorTypeTs = checker.getTypeFromTypeNode(typeNode)\n\t\t\t\tconst errorTypeName = checker.typeToString(errorTypeTs)\n\n\t\t\t\tif (!catchProperty) {\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tnode: optionsObject,\n\t\t\t\t\t\tmessageId: `missingCatchProperty`,\n\t\t\t\t\t\tdata: { functionName, errorTypeName },\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// --- New Validation: Check Constructor Types ---\n\t\t\t\tconst catchArray = catchProperty.value\n\t\t\t\tif (catchArray.type !== AST_NODE_TYPES.ArrayExpression) {\n\t\t\t\t\t// We only check array literals (e.g., [Ctor1, Ctor2])\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// 3. Collect all acceptable nominal symbols from E\n\t\t\t\tconst acceptableErrorSymbols: TsSymbol[] = []\n\n\t\t\t\t// Check if E is a Union Type\n\t\t\t\tif (errorTypeTs.isUnion()) {\n\t\t\t\t\t// Add the symbol of every member of the union (e.g., Symbol(SpecialError), Symbol(FancyError))\n\t\t\t\t\tfor (const memberType of errorTypeTs.types) {\n\t\t\t\t\t\tconst symbol = memberType.getSymbol()\n\t\t\t\t\t\tif (symbol) {\n\t\t\t\t\t\t\tacceptableErrorSymbols.push(symbol)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// E is a single type, add its symbol\n\t\t\t\t\tconst symbol = errorTypeTs.getSymbol()\n\t\t\t\t\tif (symbol) {\n\t\t\t\t\t\tacceptableErrorSymbols.push(symbol)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (catchArray.elements.length === 0) {\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tnode: catchProperty,\n\t\t\t\t\t\tmessageId: `missingCatchProperty`,\n\t\t\t\t\t\tdata: { functionName, errorTypeName },\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst errorSymbolsToRepresent = new Set(acceptableErrorSymbols)\n\n\t\t\t\t// Iterate over each constructor reference in the 'catch' array\n\t\t\t\tfor (const element of catchArray.elements) {\n\t\t\t\t\tif (element?.type !== AST_NODE_TYPES.Identifier) {\n\t\t\t\t\t\t// Only check simple identifier references (e.g., [ClientError])\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\t// Get the type of the constructor identifier (e.g., the Type of 'Error')\n\t\t\t\t\tconst constructorTsNode =\n\t\t\t\t\t\tparserServices.esTreeNodeToTSNodeMap.get(element)\n\t\t\t\t\tconst constructorType = checker.getTypeAtLocation(constructorTsNode)\n\t\t\t\t\tconst constructorName = element.name\n\n\t\t\t\t\t// console.log(`constructorName`, constructorName)\n\n\t\t\t\t\t// Extract the instance type from the constructor type.\n\t\t\t\t\t// e.g., turn 'typeof ClientError' into 'ClientError'\n\t\t\t\t\tlet instanceType: Type | undefined\n\t\t\t\t\tif (\n\t\t\t\t\t\t(constructorType as InterfaceType).getConstructSignatures().length >\n\t\t\t\t\t\t0\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Get the return type of the constructor signature\n\t\t\t\t\t\tconst signature = (\n\t\t\t\t\t\t\tconstructorType as InterfaceType\n\t\t\t\t\t\t).getConstructSignatures()[0]\n\t\t\t\t\t\tinstanceType = signature.getReturnType()\n\t\t\t\t\t}\n\n\t\t\t\t\t// If we couldn't get the instance type, skip the check\n\n\t\t\t\t\tconst constructorInstanceSymbol = instanceType?.getSymbol()\n\t\t\t\t\tif (!constructorInstanceSymbol) continue\n\n\t\t\t\t\t// Check for symbol identity\n\t\t\t\t\tif (acceptableErrorSymbols.includes(constructorInstanceSymbol)) {\n\t\t\t\t\t\terrorSymbolsToRepresent.delete(constructorInstanceSymbol)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\tnode: element,\n\t\t\t\t\t\t\tmessageId: `invalidCatchProperty`,\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tfunctionName,\n\t\t\t\t\t\t\t\tconstructorName: constructorName,\n\t\t\t\t\t\t\t\terrorTypeName: errorTypeName,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfor (const errorSymbol of errorSymbolsToRepresent) {\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tnode: catchProperty,\n\t\t\t\t\t\tmessageId: `extraneousErrorTypes`,\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\terrorTypeName: checker.symbolToString(errorSymbol),\n\t\t\t\t\t\t\tfunctionName,\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\t},\n})\n","/* eslint-disable @typescript-eslint/switch-exhaustiveness-check */\nimport { AST_NODE_TYPES, ESLintUtils } from \"@typescript-eslint/utils\"\n\nconst createRule = ESLintUtils.RuleCreator(\n\t(name) => `https://atom.io.fyi/docs/eslint-plugin#${name}`,\n)\n\nconst STATE_FUNCTIONS = [\n\t`atom`,\n\t`atomFamily`,\n\t`mutableAtom`,\n\t`mutableAtomFamily`,\n\t`selector`,\n\t`selectorFamily`,\n]\n\ntype Options = [\n\t{\n\t\tpermitAnnotation?: boolean\n\t},\n]\n\nexport const explicitStateTypes: ESLintUtils.RuleModule<\n\t`noTypeArgument` | `noTypeArgumentOrAnnotation`,\n\tOptions,\n\tunknown,\n\tESLintUtils.RuleListener\n> = createRule({\n\tname: `explicit-state-types`,\n\tmeta: {\n\t\ttype: `problem`,\n\t\tdocs: {\n\t\t\tdescription: `State declarations must have generic type arguments directly passed to them`,\n\t\t},\n\t\tmessages: {\n\t\t\tnoTypeArgument: `State declarations must have generic type arguments directly passed to them.`,\n\t\t\tnoTypeArgumentOrAnnotation: `State declarations must have generic type arguments directly passed to them, or a top-level type annotation.`,\n\t\t},\n\t\tschema: [\n\t\t\t{\n\t\t\t\ttype: `object`,\n\t\t\t\tproperties: {\n\t\t\t\t\tpermitAnnotation: {\n\t\t\t\t\t\ttype: `boolean`,\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tadditionalProperties: false,\n\t\t\t},\n\t\t],\n\t},\n\tdefaultOptions: [\n\t\t{\n\t\t\tpermitAnnotation: false,\n\t\t},\n\t],\n\tcreate(context) {\n\t\tconst options = context.options[0]\n\t\tconst permitAnnotation = options?.permitAnnotation ?? false\n\n\t\treturn {\n\t\t\tCallExpression(node) {\n\t\t\t\tconst callee = node.callee\n\n\t\t\t\tswitch (callee.type) {\n\t\t\t\t\tcase `Identifier`:\n\t\t\t\t\t\tif (STATE_FUNCTIONS.includes(callee.name) === false) {\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase `MemberExpression`:\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t(callee.property.type === `Identifier` &&\n\t\t\t\t\t\t\t\tSTATE_FUNCTIONS.includes(callee.property.name)) === false\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// Check for the *required* generic type argument first\n\t\t\t\tif (node.typeArguments) {\n\t\t\t\t\treturn // Generic type argument is present, no error\n\t\t\t\t}\n\n\t\t\t\t// If generic arguments are missing, check if the top-level annotation exception is enabled AND present\n\t\t\t\tif (permitAnnotation) {\n\t\t\t\t\tlet hasAnnotation = false\n\t\t\t\t\t// Check if the CallExpression is the initializer of a variable declarator\n\t\t\t\t\tconst parent = node.parent\n\t\t\t\t\tif (\n\t\t\t\t\t\tparent?.type === AST_NODE_TYPES.VariableDeclarator &&\n\t\t\t\t\t\tparent.init === node\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Check if the VariableDeclarator has an id with a TypeAnnotation\n\t\t\t\t\t\tconst declaratorId = parent.id\n\t\t\t\t\t\tif (declaratorId.type === AST_NODE_TYPES.Identifier) {\n\t\t\t\t\t\t\t// Check for 'const myAtom: AtomToken<string> = ...'\n\t\t\t\t\t\t\thasAnnotation = Boolean(declaratorId.typeAnnotation)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (hasAnnotation) {\n\t\t\t\t\t\treturn // Exception met: type annotation is on the variable declaration\n\t\t\t\t\t}\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tnode,\n\t\t\t\t\t\tmessageId: `noTypeArgumentOrAnnotation`,\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tcontext.report({\n\t\t\t\t\tnode,\n\t\t\t\t\tmessageId: `noTypeArgument`,\n\t\t\t\t})\n\t\t\t},\n\t\t}\n\t},\n})\n","import type { RuleType } from \"@eslint/core\"\nimport type { Rule } from \"eslint\"\nimport type * as ESTree from \"estree\"\n\nconst SUFFIX_DICTIONARY = {\n\tatom: `Atom`,\n\tatomFamily: `Atoms`,\n\tmutableAtom: `Atom`,\n\tmutableAtomFamily: `Atoms`,\n\tselector: `Selector`,\n\tselectorFamily: `Selectors`,\n} as const\n\nconst PLURAL_DICTIONARY = {\n\tatom: `atoms`,\n\tatomFamily: `atom families`,\n\tmutableAtom: `atoms`,\n\tmutableAtomFamily: `atom families`,\n\tselector: `selectors`,\n\tselectorFamily: `selector families`,\n}\n\ntype StateFunctionName = keyof typeof SUFFIX_DICTIONARY\n\nexport const namingConvention: {\n\tmeta: {\n\t\ttype: RuleType\n\t\tdocs: {\n\t\t\tdescription: string\n\t\t\tcategory: string\n\t\t\trecommended: boolean\n\t\t\turl: string\n\t\t}\n\t\tfixable: `code`\n\t\tschema: never[]\n\t}\n\tcreate(context: Rule.RuleContext): Rule.NodeListener\n} = {\n\tmeta: {\n\t\ttype: `problem`,\n\t\tdocs: {\n\t\t\tdescription: `The variable names given to atoms, selectors, and their respective families should match their given key property, and should follow a consistent format`,\n\t\t\tcategory: `Best Practices`,\n\t\t\trecommended: false,\n\t\t\turl: ``,\n\t\t},\n\t\tfixable: `code`,\n\t\tschema: [],\n\t},\n\n\tcreate(context) {\n\t\treturn {\n\t\t\tCallExpression(node) {\n\t\t\t\t// atom(...)\n\t\t\t\tif (\n\t\t\t\t\tnode.callee.type !== `Identifier` &&\n\t\t\t\t\tnode.callee.type !== `MemberExpression`\n\t\t\t\t) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\t// Must be assigned: const x = atom(...)\n\t\t\t\tif (node.parent?.type !== `VariableDeclarator`) return\n\t\t\t\tif (node.parent.init !== node) return\n\t\t\t\tif (node.parent.id.type !== `Identifier`) return\n\n\t\t\t\tlet calleeName: StateFunctionName\n\n\t\t\t\tswitch (node.callee.type) {\n\t\t\t\t\tcase `Identifier`:\n\t\t\t\t\t\tcalleeName = node.callee.name as StateFunctionName\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase `MemberExpression`:\n\t\t\t\t\t\tif (node.callee.property.type !== `Identifier`) return\n\t\t\t\t\t\tcalleeName = node.callee.property.name as StateFunctionName\n\t\t\t\t\t\tbreak\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tswitch (calleeName) {\n\t\t\t\t\tcase `atom`:\n\t\t\t\t\tcase `atomFamily`:\n\t\t\t\t\tcase `mutableAtom`:\n\t\t\t\t\tcase `mutableAtomFamily`:\n\t\t\t\t\tcase `selector`:\n\t\t\t\t\tcase `selectorFamily`:\n\t\t\t\t\t\tbreak // ^ targets of this rule\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst suffix = SUFFIX_DICTIONARY[calleeName]\n\t\t\t\tconst plural = PLURAL_DICTIONARY[calleeName]\n\n\t\t\t\tconst variableName = node.parent.id.name\n\n\t\t\t\t// Enforce FooAtom naming\n\t\t\t\tif (!variableName.endsWith(suffix)) {\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tnode: node.parent.id,\n\t\t\t\t\t\tmessage: `Names of ${plural} should end with '${suffix}'.`,\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst expectedKey = variableName.slice(0, -suffix.length)\n\n\t\t\t\t// Must have first argument object\n\t\t\t\tconst arg = node.arguments[0]\n\t\t\t\tif (arg?.type !== `ObjectExpression`) return\n\n\t\t\t\t// Find key property\n\t\t\t\tconst keyProp = arg.properties.find(\n\t\t\t\t\t(prop): prop is ESTree.Property =>\n\t\t\t\t\t\tprop.type === `Property` &&\n\t\t\t\t\t\t((prop.key.type === `Identifier` && prop.key.name === `key`) ||\n\t\t\t\t\t\t\t(prop.key.type === `Literal` && prop.key.value === `key`)),\n\t\t\t\t)\n\n\t\t\t\tif (!keyProp) return\n\n\t\t\t\t// Must be string literal or template literal\n\t\t\t\tif (\n\t\t\t\t\tkeyProp.value.type !== `Literal` ||\n\t\t\t\t\ttypeof keyProp.value.value !== `string`\n\t\t\t\t) {\n\t\t\t\t\tif (keyProp.value.type !== `TemplateLiteral`) return\n\t\t\t\t}\n\n\t\t\t\tconst actualKey =\n\t\t\t\t\tkeyProp.value.type === `Literal`\n\t\t\t\t\t\t? keyProp.value.value\n\t\t\t\t\t\t: keyProp.value.quasis[0].value.raw\n\n\t\t\t\tif (\n\t\t\t\t\tactualKey !== expectedKey ||\n\t\t\t\t\t(`quasis` in keyProp.value && keyProp.value.quasis.length > 1)\n\t\t\t\t) {\n\t\t\t\t\tcontext.report({\n\t\t\t\t\t\tnode: keyProp.value,\n\t\t\t\t\t\tmessage: `Keys of ${plural} should be consistent with the names of their variables.`,\n\t\t\t\t\t\tfix(fixer) {\n\t\t\t\t\t\t\treturn fixer.replaceText(\n\t\t\t\t\t\t\t\tkeyProp.value,\n\t\t\t\t\t\t\t\tJSON.stringify(expectedKey),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\t},\n} satisfies Rule.RuleModule\n","export * from \"./exact-catch-types\"\nexport * from \"./explicit-state-types\"\nexport * from \"./naming-convention\"\n","import type { ESLint } from \"eslint\"\n\nimport * as Rules from \"./rules\"\n\nexport { Rules }\n\nconst plugin: ESLint.Plugin = {\n\trules: {\n\t\t\"naming-convention\": Rules.namingConvention as any,\n\t\t\"exact-catch-types\": Rules.exactCatchTypes as any,\n\t\t\"explicit-state-types\": Rules.explicitStateTypes as any,\n\t},\n} satisfies ESLint.Plugin\n\nexport default plugin\n"],"mappings":";;;;AASA,MAAMA,eAAa,YAAY,aAC7B,SAAS,0CAA0C,OACpD;AAED,MAAM,6BAA6B;CAClC;CACA;CACA;CACA;CACA;AACD,MAAM,mBAAmB,CAAC,cAAc,iBAAiB;AAEzD,MAAa,kBAKTA,aAAW;CACd,MAAM;CACN,MAAM;EACL,MAAM;EACN,MAAM,EACL,aAAa,2IACb;EACD,UAAU;GACT,sBACC;GAGD,sBACC;GAID,sBACC;GAGD;EACD,QAAQ,EAAE;EACV;CACD,gBAAgB,EAAE;CAClB,OAAO,SAAS;EACf,MAAM,iBAAiB,YAAY,kBAAkB,QAAQ;EAC7D,MAAM,UAAU,eAAe,QAAQ,gBAAgB;AAEvD,SAAO,EACN,eAAe,MAAM;GACpB,MAAM,EACL,QACA,eAAe,qBACf,WAAW,kBACR;GAEJ,IAAI,kBAAkB;GAGtB,IAAI,eAA8B;AAClC,OAAI,OAAO,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AGnB,eACb,YAAY,QAAQ,SAAS,QAAQ,MAAM,OAAO,SAAS,EAE5D,SAAQ,OAAO;IACd,MAAM,QAAQ;IACd,SAAS,WAAW,OAAO;IAC3B,IAAI,OAAO;AACV,YAAO,MAAM,YACZ,QAAQ,OACR,KAAK,UAAU,YAAY,CAC3B;;IAEF,CAAC;KAGJ;;CAEF;;;;;;;;;;;;AElJD,MAAM,SAAwB,EAC7B,OAAO;CACN,qBAAqBC;CACrB,qBAAqBC;CACrB,wBAAwBC;CACxB,EACD"}
@@ -15,7 +15,7 @@ declare function useAtomicRef<T, R extends {
15
15
  }>(token: RegularAtomToken<T | null>, useRef: <TT>(initialValue: TT | null) => R): R;
16
16
  declare function useAtomicRef<T, K extends Canonical, R extends {
17
17
  current: T | null;
18
- }>(token: RegularAtomFamilyToken<T | null, string>, key: NoInfer<K>, useRef: <TT>(initialValue: TT | null) => R): R;
18
+ }>(token: RegularAtomFamilyToken<T | null, K>, key: NoInfer<K>, useRef: <TT>(initialValue: TT | null) => R): R;
19
19
  //#endregion
20
20
  //#region src/react/use-i.d.ts
21
21
  declare function useI<T>(token: WritableToken<T, any, any>): <New extends T>(next: New | ((old: T) => New)) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/react/store-context.tsx","../../src/react/use-atomic-ref.ts","../../src/react/use-i.ts","../../src/react/use-json.ts","../../src/react/use-loadable.ts","../../src/react/use-o.ts","../../src/react/use-single-effect.ts","../../src/react/use-tl.ts"],"mappings":";;;;;cAIa,YAAA,EAAc,KAAA,CAAM,OAAA,CAAQ,SAAA;AAAA,cAI5B,aAAA,EAAe,KAAA,CAAM,EAAA;EACjC,QAAA,EAAU,KAAA,CAAM,SAAA;EAChB,KAAA,GAAQ,SAAA;AAAA;;;iBCEO,YAAA;EAA4B,OAAA,EAAS,CAAA;AAAA,EAAA,CACpD,KAAA,EAAO,gBAAA,CAAiB,CAAA,UACxB,MAAA,OAAa,YAAA,EAAc,EAAA,YAA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,EAAO,aAAA,CAAc,QAAA,CAAS,CAAA,QAAS,CAAA,GACvC,QAAA,EAAU,CAAA;EACN,OAAA;EAAkB,KAAA,EAAO,MAAA,CAAO,CAAA;EAAI,KAAA,GAAQ,CAAA;AAAA;AAAA,iBAEjC,WAAA,cAAyB,SAAA,YAAqB,CAAA,IAAA,CAC7D,KAAA,EAAO,mBAAA,CAAoB,QAAA,CAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAC3C,GAAA,EAAK,OAAA,CAAQ,CAAA,GACb,QAAA,EAAU,CAAA;EACN,OAAA;EAAkB,KAAA,EAAO,MAAA,CAAO,CAAA;EAAI,KAAA,GAAQ,CAAA;AAAA;;;iBCbjC,IAAA,cAAA,CACf,KAAA,EAAO,aAAA,CAAc,CAAA,OAAQ,CAAA,IAC3B,MAAA,CAAO,CAAA,GAAI,CAAA;AAAA,iBAEE,IAAA,cAAkB,SAAA,YAAA,CACjC,KAAA,EAAO,mBAAA,CAAoB,CAAA,EAAG,CAAA,EAAG,CAAA,GACjC,GAAA,EAAK,OAAA,CAAQ,CAAA,IACX,MAAA,CAAO,CAAA,GAAI,CAAA;;;iBCnBE,eAAA,CACf,MAAA,yCACA,IAAA;;;KCAW,YAAA;EACX,EAAA;EACA,MAAA;EACA,IAAA;EACA,IAAA;AAAA;AAAA,iBAGe,KAAA,CAAM,KAAA,EAAO,aAAA,QAAqB,YAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/react/store-context.tsx","../../src/react/use-atomic-ref.ts","../../src/react/use-i.ts","../../src/react/use-json.ts","../../src/react/use-loadable.ts","../../src/react/use-o.ts","../../src/react/use-single-effect.ts","../../src/react/use-tl.ts"],"mappings":";;;;;cAIa,YAAA,EAAc,KAAA,CAAM,OAAA,CAAQ,SAAA;AAAA,cAI5B,aAAA,EAAe,KAAA,CAAM,EAAA;EACjC,QAAA,EAAU,KAAA,CAAM,SAAA;EAChB,KAAA,GAAQ,SAAA;AAAA;;;iBCCO,YAAA;E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,CAAA;EACG,OAAA;EAAkB,KAAA,EAAO,MAAA,CAAO,CAAA,GAAI,CAAA;AAAA;AAAA,iBAErC,WAAA,cAAyB,CAAA,IAAA,CACxC,KAAA,EAAO,aAAA,CAAc,QAAA,CAAS,CAAA,QAAS,CAAA,GACvC,QAAA,EAAU,CAAA;EACN,OAAA;EAAkB,KAAA,EAAO,MAAA,CAAO,CAAA;EAAI,KAAA,GAAQ,CAAA;AAAA;AAAA,iBAEjC,WAAA,cAAyB,SAAA,YAAqB,CAAA,IAAA,CAC7D,KAAA,EAAO,mBAAA,CAAoB,QAAA,CAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAC3C,GAAA,EAAK,OAAA,CAAQ,CAAA,GACb,QAAA,EAAU,CAAA;EACN,OAAA;EAAkB,KAAA,EAAO,MAAA,CAAO,CAAA;EAAI,KAAA,GAAQ,CAAA;AAAA;;;iBCbjC,IAAA,cAAA,CACf,KAAA,EAAO,aAAA,CAAc,CAAA,OAAQ,CAAA,IAC3B,MAAA,CAAO,CAAA,GAAI,CAAA;AAAA,iBAEE,IAAA,cAAkB,SAAA,YAAA,CACjC,KAAA,EAAO,mBAAA,CAAoB,CAAA,EAAG,CAAA,EAAG,CAAA,GACjC,GAAA,EAAK,OAAA,CAAQ,CAAA,IACX,MAAA,CAAO,CAAA,GAAI,CAAA;;;iBCnBE,eAAA,CACf,MAAA,yCACA,IAAA;;;KCAW,YAAA;EACX,EAAA;EACA,MAAA;EACA,IAAA;EACA,IAAA;AAAA;AAAA,iBAGe,KAAA,CAAM,KAAA,EAAO,aAAA,QAAqB,YAAA"}
@@ -1,5 +1,5 @@
1
1
  import { IMPLICIT, findInStore, getFromStore, getJsonToken, isFn, setIntoStore, subscribeToState, subscribeToTimeline, withdraw } from "atom.io/internal";
2
- import { redo, setState, undo } from "atom.io";
2
+ import { redo, undo } from "atom.io";
3
3
  import * as React from "react";
4
4
  import { createContext, useCallback, useContext, useEffect, useId, useRef, useState, useSyncExternalStore } from "react";
5
5
  import { jsx } from "react/jsx-runtime";
@@ -29,7 +29,7 @@ function useAtomicRef(...params) {
29
29
  }
30
30
  const ref = useRef(null);
31
31
  useEffect(() => {
32
- setState(token, ref.current);
32
+ setIntoStore(store, token, ref.current);
33
33
  }, [token]);
34
34
  return ref;
35
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["StoreContext","useO"],"sources":["../../src/react/store-context.tsx","../../src/react/use-atomic-ref.ts","../../src/react/parse-state-overloads.ts","../../src/react/use-i.ts","../../src/react/use-single-effect.ts","../../src/react/use-o.ts","../../src/react/use-json.ts","../../src/react/use-loadable.ts","../../src/react/use-tl.ts"],"sourcesContent":["import type { RootStore } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport { createContext } from \"react\"\n\nexport const StoreContext: React.Context<RootStore> = createContext(\n\tIMPLICIT.STORE,\n)\n\nexport const StoreProvider: React.FC<{\n\tchildren: React.ReactNode\n\tstore?: RootStore\n}> = ({ children, store = IMPLICIT.STORE }) => (\n\t<StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n)\n","import type {\n\tAtomToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n} from \"atom.io\"\nimport { setState } from \"atom.io\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport { useContext, useEffect } from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport function useAtomicRef<T, R extends { current: T | null }>(\n\ttoken: RegularAtomToken<T | null>,\n\tuseRef: <TT>(initialValue: TT | null) => R,\n): R\n\nexport function useAtomicRef<\n\tT,\n\tK extends Canonical,\n\tR extends { current: T | null },\n>(\n\ttoken: RegularAtomFamilyToken<T | null, string>,\n\tkey: NoInfer<K>,\n\tuseRef: <TT>(initialValue: TT | null) => R,\n): R\n\nexport function useAtomicRef<\n\tT,\n\tK extends Canonical,\n\tR extends { current: T | null },\n>(\n\t...params:\n\t\t| [\n\t\t\t\tRegularAtomFamilyToken<T | null, K>,\n\t\t\t\tNoInfer<K>,\n\t\t\t\t<TT>(initialValue: TT | null) => R,\n\t\t ]\n\t\t| [RegularAtomToken<T | null>, <TT>(initialValue: TT | null) => R]\n): R {\n\tlet token: AtomToken<T | null>\n\tlet useRef: <TT>(initialValue: TT | null) => R\n\tconst store = useContext(StoreContext)\n\tif (params.length === 3) {\n\t\tconst family = params[0]\n\t\tconst key = params[1]\n\t\ttoken = findInStore(store, family, key)\n\t\tuseRef = params[2]\n\t} else {\n\t\ttoken = params[0]\n\t\tuseRef = params[1]\n\t}\n\tconst ref = useRef(null)\n\tuseEffect(() => {\n\t\tsetState(token, ref.current)\n\t}, [token])\n\treturn ref\n}\n","import type {\n\tReadableFamilyToken,\n\tReadableToken,\n\tWritableFamilyToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\n\nexport function parseStateOverloads<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\t...rest: [WritableFamilyToken<T, K, E>, Key] | [WritableToken<T, any, E>]\n): WritableToken<T, Key, E>\n\nexport function parseStateOverloads<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\t...rest: [ReadableFamilyToken<T, K, E>, Key] | [ReadableToken<T, any, E>]\n): ReadableToken<T, Key, E>\n\nexport function parseStateOverloads<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\t...rest: [ReadableFamilyToken<T, K, E>, Key] | [ReadableToken<T, any, E>]\n): ReadableToken<T, Key, E> {\n\tlet token: ReadableToken<any, any, any>\n\tif (rest.length === 2) {\n\t\tconst family = rest[0]\n\t\tconst key = rest[1]\n\n\t\ttoken = findInStore(store, family, key)\n\t} else {\n\t\ttoken = rest[0]\n\t}\n\treturn token\n}\n","import type { WritableFamilyToken, WritableToken } from \"atom.io\"\nimport { setIntoStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport { useContext, useRef } from \"react\"\n\nimport { parseStateOverloads } from \"./parse-state-overloads\"\nimport { StoreContext } from \"./store-context\"\n\nexport function useI<T>(\n\ttoken: WritableToken<T, any, any>,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Canonical>(\n\ttoken: WritableFamilyToken<T, K, any>,\n\tkey: NoInfer<K>,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Canonical>(\n\t...params:\n\t\t| [WritableFamilyToken<T, K, any>, NoInfer<K>]\n\t\t| [WritableToken<T, any, any>]\n): <New extends T>(next: New | ((old: T) => New)) => void {\n\tconst store = useContext(StoreContext)\n\tconst token = parseStateOverloads(store, ...params)\n\tconst setter: React.RefObject<\n\t\t(<New extends T>(next: New | ((old: T) => New)) => void) | null\n\t> = useRef(null)\n\tsetter.current ??= (next) => {\n\t\tsetIntoStore(store, token, next)\n\t}\n\treturn setter.current\n}\n","/** biome-ignore-all lint/correctness/useHookAtTopLevel: intentional */\n\nimport { isFn } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nexport function useSingleEffect(\n\teffect: () => (() => void) | undefined | void,\n\tdeps: unknown[],\n): void {\n\tconst globalEnv = (globalThis as unknown as { env: any })[`env`]\n\tconst isInDev = globalEnv?.NODE_ENV === `development`\n\tif (isInDev) {\n\t\tconst cleanupRef = React.useRef<boolean | (() => void)>(false)\n\t\tReact.useEffect(() => {\n\t\t\tlet cleanupFn = cleanupRef.current\n\t\t\tif (cleanupFn === false) {\n\t\t\t\tcleanupFn = effect() ?? true\n\t\t\t\tcleanupRef.current = cleanupFn\n\t\t\t} else {\n\t\t\t\treturn () => {\n\t\t\t\t\tif (isFn(cleanupFn)) cleanupFn()\n\t\t\t\t\tcleanupRef.current = false\n\t\t\t\t}\n\t\t\t}\n\t\t}, deps)\n\t} else {\n\t\tReact.useEffect(effect, deps)\n\t}\n}\n","/** biome-ignore-all lint/correctness/useHookAtTopLevel: depends on the type of atom, which shouldn't change */\nimport type { ReadableFamilyToken, ReadableToken, ViewOf } from \"atom.io\"\nimport { getFromStore, subscribeToState } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport {\n\tuseCallback,\n\tuseContext,\n\tuseId,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from \"react\"\n\nimport { parseStateOverloads } from \"./parse-state-overloads\"\nimport { StoreContext } from \"./store-context\"\nimport { useSingleEffect } from \"./use-single-effect\"\n\nexport function useO<T, E = never>(\n\ttoken: ReadableToken<T, any, E>,\n): ViewOf<E | T>\n\nexport function useO<T, K extends Canonical, E = never>(\n\ttoken: ReadableFamilyToken<T, K, E>,\n\tkey: NoInfer<K>,\n): ViewOf<E | T>\n\nexport function useO<T, K extends Canonical, E = never>(\n\t...params:\n\t\t| [ReadableFamilyToken<T, K, E>, NoInfer<K>]\n\t\t| [ReadableToken<T, any, E>]\n): ViewOf<E | T> {\n\tconst store = useContext(StoreContext)\n\tconst token = parseStateOverloads(store, ...params)\n\tconst id = useId()\n\n\tif (\n\t\ttoken.type === `mutable_atom` ||\n\t\ttoken.type === `readonly_held_selector` ||\n\t\ttoken.type === `writable_held_selector`\n\t) {\n\t\tconst [, dispatch] = useState<number>(0)\n\t\tconst valueRef = useRef<ViewOf<E | T>>(getFromStore(store, token))\n\t\tuseSingleEffect(() => {\n\t\t\tconst unsub = subscribeToState<T, E>(\n\t\t\t\tstore,\n\t\t\t\ttoken,\n\t\t\t\t`use-o:${id}`,\n\t\t\t\t({ newValue }) => {\n\t\t\t\t\tvalueRef.current = newValue\n\t\t\t\t\tdispatch((c) => c + 1)\n\t\t\t\t},\n\t\t\t)\n\t\t\treturn unsub\n\t\t}, [token.key])\n\t\treturn valueRef.current\n\t}\n\n\tconst sub = useCallback(\n\t\t(dispatch: () => void) =>\n\t\t\tsubscribeToState<T, E>(store, token, `use-o:${id}`, dispatch),\n\t\t[token.key],\n\t)\n\tconst get = useCallback(() => getFromStore(store, token), [token.key])\n\treturn useSyncExternalStore<ViewOf<E | T>>(sub, get, get)\n}\n","import type { MutableAtomFamilyToken, MutableAtomToken } from \"atom.io\"\nimport type { AsJSON, Transceiver } from \"atom.io/internal\"\nimport { findInStore, getJsonToken } from \"atom.io/internal\"\nimport type { Canonical, Json } from \"atom.io/json\"\nimport { useContext } from \"react\"\n\nimport { StoreContext } from \"./store-context\"\nimport { useO } from \"./use-o\"\n\nexport function useJSON<T extends Transceiver<any, any, any>>(\n\ttoken: MutableAtomToken<T>,\n): AsJSON<T>\n\nexport function useJSON<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n>(token: MutableAtomFamilyToken<T, K>, key: NoInfer<K>): AsJSON<T>\n\nexport function useJSON(\n\ttoken: MutableAtomFamilyToken<any, any> | MutableAtomToken<any>,\n\tkey?: Canonical,\n): Json.Serializable {\n\tconst store = useContext(StoreContext)\n\tconst stateToken: MutableAtomToken<any> =\n\t\ttoken.type === `mutable_atom_family` ? findInStore(store, token, key) : token\n\tconst jsonToken = getJsonToken(store, stateToken)\n\treturn useO(jsonToken)\n}\n","/** biome-ignore-all lint/correctness/useHookAtTopLevel: params are used in an invariant way */\nimport type {\n\tLoadable,\n\tReadableFamilyToken,\n\tReadableToken,\n\tViewOf,\n} from \"atom.io\"\nimport { findInStore, type ReadableState, withdraw } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport { useContext, useRef } from \"react\"\n\nexport function useLoadable<T, E>(\n\ttoken: ReadableToken<Loadable<T>, any, E>,\n): `LOADING` | { loading: boolean; value: ViewOf<E | T> }\n\nexport function useLoadable<T, K extends Canonical, E>(\n\ttoken: ReadableFamilyToken<Loadable<T>, K, E>,\n\tkey: NoInfer<K>,\n): `LOADING` | { loading: boolean; value: ViewOf<E | T> }\n\nexport function useLoadable<T, F extends T, E>(\n\ttoken: ReadableToken<Loadable<T>, any, E>,\n\tfallback: F,\n): { loading: boolean; value: ViewOf<T>; error?: E }\n\nexport function useLoadable<T, K extends Canonical, F extends T, E>(\n\ttoken: ReadableFamilyToken<Loadable<T>, K, E>,\n\tkey: NoInfer<K>,\n\tfallback: F,\n): { loading: boolean; value: ViewOf<T>; error?: E }\n\nexport function useLoadable(\n\t...params:\n\t\t| readonly [ReadableFamilyToken<any, Canonical, any>, Canonical, unknown]\n\t\t| readonly [ReadableFamilyToken<any, Canonical, any>, Canonical]\n\t\t| readonly [ReadableToken<any, any, any>, unknown]\n\t\t| readonly [ReadableToken<any, any, any>]\n): `LOADING` | { loading: boolean; value: unknown; error?: unknown } {\n\tconst store = useContext(StoreContext)\n\n\tlet value: unknown\n\tlet state: ReadableState<any, any>\n\tlet fallback: unknown\n\n\tconst [token] = params\n\tlet key: Canonical\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\tcase `readonly_held_selector`:\n\t\tcase `readonly_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\tcase `writable_pure_selector`:\n\t\t\tvalue = useO(token)\n\t\t\tstate = withdraw(store, token)\n\t\t\tfallback = params[1]\n\t\t\tbreak\n\t\tcase `atom_family`:\n\t\tcase `mutable_atom_family`:\n\t\tcase `readonly_held_selector_family`:\n\t\tcase `readonly_pure_selector_family`:\n\t\tcase `writable_held_selector_family`:\n\t\tcase `writable_pure_selector_family`:\n\t\t\tkey = params[1] as Canonical\n\t\t\tvalue = useO(token, key)\n\t\t\tstate = withdraw(store, findInStore(store, token, key))\n\t\t\tfallback = params[2]\n\t}\n\n\tconst hasFallback = fallback !== undefined\n\tconst isErr = `catch` in state && state.catch.some((E) => value instanceof E)\n\n\tconst wrapperRef = useRef<{\n\t\tloading: boolean\n\t\tvalue: unknown\n\t\terror?: unknown\n\t}>({ loading: false, value: null as unknown })\n\tconst lastLoadedRef = useRef(\n\t\tfallback ?? (value instanceof Promise ? `LOADING` : value),\n\t)\n\n\tconst { current: lastLoaded } = lastLoadedRef\n\tlet { current: wrapper } = wrapperRef\n\n\tconst wasErr =\n\t\t`catch` in state && state.catch.some((E) => lastLoaded instanceof E)\n\n\tif (value instanceof Promise) {\n\t\tif (lastLoaded === `LOADING`) {\n\t\t\treturn `LOADING`\n\t\t}\n\t\tif (wasErr && hasFallback) {\n\t\t\twrapper = wrapperRef.current = {\n\t\t\t\tloading: true,\n\t\t\t\tvalue: fallback,\n\t\t\t\terror: lastLoaded,\n\t\t\t}\n\t\t} else {\n\t\t\twrapper = wrapperRef.current = { loading: true, value: lastLoaded }\n\t\t}\n\t} else {\n\t\tlastLoadedRef.current = value\n\t\tif (wrapper.loading === true) {\n\t\t\tif (isErr && hasFallback) {\n\t\t\t\twrapper = wrapperRef.current = {\n\t\t\t\t\tloading: false,\n\t\t\t\t\tvalue: fallback,\n\t\t\t\t\terror: value,\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\twrapper = wrapperRef.current = { loading: false, value: value }\n\t\t\t}\n\t\t} else {\n\t\t\tif (isErr && hasFallback) {\n\t\t\t\twrapper.loading = false\n\t\t\t\twrapper.value = fallback\n\t\t\t\twrapper.error = value\n\t\t\t} else {\n\t\t\t\twrapper.loading = false\n\t\t\t\twrapper.value = value\n\t\t\t\tdelete wrapper.error\n\t\t\t}\n\t\t}\n\t}\n\n\treturn wrapper\n}\n","import type { TimelineToken } from \"atom.io\"\nimport { redo, undo } from \"atom.io\"\nimport { subscribeToTimeline, withdraw } from \"atom.io/internal\"\nimport { useContext, useId, useRef, useSyncExternalStore } from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport type TimelineMeta = {\n\tat: number\n\tlength: number\n\tundo: () => void\n\tredo: () => void\n}\n\nexport function useTL(token: TimelineToken<any>): TimelineMeta {\n\tconst store = useContext(StoreContext)\n\tconst id = useId()\n\tconst timeline = withdraw(store, token)\n\tconst tokenRef = useRef(token)\n\tconst rebuildMeta = () => {\n\t\treturn {\n\t\t\tat: timeline.at,\n\t\t\tlength: timeline.history.length,\n\t\t\tundo: () => {\n\t\t\t\tundo(token)\n\t\t\t},\n\t\t\tredo: () => {\n\t\t\t\tredo(token)\n\t\t\t},\n\t\t}\n\t}\n\tconst meta = useRef<TimelineMeta>(rebuildMeta())\n\tconst retrieve = () => {\n\t\tif (\n\t\t\tmeta.current.at !== timeline?.at ||\n\t\t\tmeta.current.length !== timeline?.history.length ||\n\t\t\ttokenRef.current !== token\n\t\t) {\n\t\t\ttokenRef.current = token\n\t\t\tmeta.current = rebuildMeta()\n\t\t}\n\t\treturn meta.current\n\t}\n\treturn useSyncExternalStore<TimelineMeta>(\n\t\t(dispatch) => subscribeToTimeline(store, token, `use-tl:${id}`, dispatch),\n\t\tretrieve,\n\t\tretrieve,\n\t)\n}\n"],"mappings":";;;;;;;;AAIA,MAAa,eAAyC,cACrD,SAAS,MACT;AAED,MAAa,iBAGP,EAAE,UAAU,QAAQ,SAAS,YAClC,oBAAC,aAAa;CAAS,OAAO;CAAQ;EAAiC;;;;ACexE,SAAgB,aAKf,GAAG,QAOC;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM,QAAQ,WAAW,aAAa;AACtC,KAAI,OAAO,WAAW,GAAG;EACxB,MAAM,SAAS,OAAO;EACtB,MAAM,MAAM,OAAO;AACnB,UAAQ,YAAY,OAAO,QAAQ,IAAI;AACvC,WAAS,OAAO;QACV;AACN,UAAQ,OAAO;AACf,WAAS,OAAO;;CAEjB,MAAM,MAAM,OAAO,KAAK;AACxB,iBAAgB;AACf,WAAS,OAAO,IAAI,QAAQ;IAC1B,CAAC,MAAM,CAAC;AACX,QAAO;;;;;ACpCR,SAAgB,oBACf,OACA,GAAG,MACwB;CAC3B,IAAI;AACJ,KAAI,KAAK,WAAW,GAAG;EACtB,MAAM,SAAS,KAAK;EACpB,MAAM,MAAM,KAAK;AAEjB,UAAQ,YAAY,OAAO,QAAQ,IAAI;OAEvC,SAAQ,KAAK;AAEd,QAAO;;;;;AChBR,SAAgB,KACf,GAAG,QAGsD;CACzD,MAAM,QAAQ,WAAW,aAAa;CACtC,MAAM,QAAQ,oBAAoB,OAAO,GAAG,OAAO;CACnD,MAAM,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AAS;GAAc;GAAO;WAG5D,SAAS,aAAa;AACzB,WAAQ,UAAU;AAClB,WAAQ,QAAQ;AAChB,WAAQ,QAAQ;SACV;AACN,WAAQ,UAAU;AAClB,WAAQ,QAAQ;AAChB,UAAO,QAAQ;;;AAKlB,QAAO;;;;;AChHR,SAAgB,MAAM,OAAyC;CAC9D,MAAM,QAAQ,WAAW,aAAa;CACtC,MAAM,KAAK,OAAO;CAClB,MAAM,WAAW,SAAS,OAAO,MAAM;CACvC,MAAM,WAAW,OAAO,MAAM;CAC9B,MAAM,oBAAoB;AACzB,SAAO;GACN,IAAI,SAAS;GACb,QAAQ,SAAS,QAAQ;GACzB,YAAY;AACX,SAAK,MAAM;;GAEZ,YAAY;AACX,SAAK,MAAM;;GAEZ;;CAEF,MAAM,OAAO,OAAqB,aAAa,CAAC;CAChD,MAAM,iBAAiB;AACtB,MACC,KAAK,QAAQ,OAAO,UAAU,MAC9B,KAAK,QAAQ,WAAW,UAAU,QAAQ,UAC1C,SAAS,YAAY,OACpB;AACD,YAAS,UAAU;AACnB,QAAK,UAAU,aAAa;;AAE7B,SAAO,KAAK;;AAEb,QAAO,sBACL,aAAa,oBAAoB,OAAO,OAAO,UAAU,MAAM,SAAS,EACzE,UACA,SACA"}
1
+ {"version":3,"file":"index.js","names":["StoreContext","useO"],"sources":["../../src/react/store-context.tsx","../../src/react/use-atomic-ref.ts","../../src/react/parse-state-overloads.ts","../../src/react/use-i.ts","../../src/react/use-single-effect.ts","../../src/react/use-o.ts","../../src/react/use-json.ts","../../src/react/use-loadable.ts","../../src/react/use-tl.ts"],"sourcesContent":["import type { RootStore } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport { createContext } from \"react\"\n\nexport const StoreContext: React.Context<RootStore> = createContext(\n\tIMPLICIT.STORE,\n)\n\nexport const StoreProvider: React.FC<{\n\tchildren: React.ReactNode\n\tstore?: RootStore\n}> = ({ children, store = IMPLICIT.STORE }) => (\n\t<StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n)\n","import type {\n\tAtomToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n} from \"atom.io\"\nimport { findInStore, setIntoStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport { useContext, useEffect } from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport function useAtomicRef<T, R extends { current: T | null }>(\n\ttoken: RegularAtomToken<T | null>,\n\tuseRef: <TT>(initialValue: TT | null) => R,\n): R\n\nexport function useAtomicRef<\n\tT,\n\tK extends Canonical,\n\tR extends { current: T | null },\n>(\n\ttoken: RegularAtomFamilyToken<T | null, K>,\n\tkey: NoInfer<K>,\n\tuseRef: <TT>(initialValue: TT | null) => R,\n): R\n\nexport function useAtomicRef<\n\tT,\n\tK extends Canonical,\n\tR extends { current: T | null },\n>(\n\t...params:\n\t\t| [\n\t\t\t\tRegularAtomFamilyToken<T | null, K>,\n\t\t\t\tNoInfer<K>,\n\t\t\t\t<TT>(initialValue: TT | null) => R,\n\t\t ]\n\t\t| [RegularAtomToken<T | null>, <TT>(initialValue: TT | null) => R]\n): R {\n\tlet token: AtomToken<T | null>\n\tlet useRef: <TT>(initialValue: TT | null) => R\n\tconst store = useContext(StoreContext)\n\tif (params.length === 3) {\n\t\tconst family = params[0]\n\t\tconst key = params[1]\n\t\ttoken = findInStore(store, family, key)\n\t\tuseRef = params[2]\n\t} else {\n\t\ttoken = params[0]\n\t\tuseRef = params[1]\n\t}\n\tconst ref = useRef(null)\n\tuseEffect(() => {\n\t\tsetIntoStore(store, token, ref.current)\n\t}, [token])\n\treturn ref\n}\n","import type {\n\tReadableFamilyToken,\n\tReadableToken,\n\tWritableFamilyToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\n\nexport function parseStateOverloads<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\t...rest: [WritableFamilyToken<T, K, E>, Key] | [WritableToken<T, any, E>]\n): WritableToken<T, Key, E>\n\nexport function parseStateOverloads<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\t...rest: [ReadableFamilyToken<T, K, E>, Key] | [ReadableToken<T, any, E>]\n): ReadableToken<T, Key, E>\n\nexport function parseStateOverloads<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\t...rest: [ReadableFamilyToken<T, K, E>, Key] | [ReadableToken<T, any, E>]\n): ReadableToken<T, Key, E> {\n\tlet token: ReadableToken<any, any, any>\n\tif (rest.length === 2) {\n\t\tconst family = rest[0]\n\t\tconst key = rest[1]\n\n\t\ttoken = findInStore(store, family, key)\n\t} else {\n\t\ttoken = rest[0]\n\t}\n\treturn token\n}\n","import type { WritableFamilyToken, WritableToken } from \"atom.io\"\nimport { setIntoStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport { useContext, useRef } from \"react\"\n\nimport { parseStateOverloads } from \"./parse-state-overloads\"\nimport { StoreContext } from \"./store-context\"\n\nexport function useI<T>(\n\ttoken: WritableToken<T, any, any>,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Canonical>(\n\ttoken: WritableFamilyToken<T, K, any>,\n\tkey: NoInfer<K>,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Canonical>(\n\t...params:\n\t\t| [WritableFamilyToken<T, K, any>, NoInfer<K>]\n\t\t| [WritableToken<T, any, any>]\n): <New extends T>(next: New | ((old: T) => New)) => void {\n\tconst store = useContext(StoreContext)\n\tconst token = parseStateOverloads(store, ...params)\n\tconst setter: React.RefObject<\n\t\t(<New extends T>(next: New | ((old: T) => New)) => void) | null\n\t> = useRef(null)\n\tsetter.current ??= (next) => {\n\t\tsetIntoStore(store, token, next)\n\t}\n\treturn setter.current\n}\n","/** biome-ignore-all lint/correctness/useHookAtTopLevel: intentional */\n\nimport { isFn } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nexport function useSingleEffect(\n\teffect: () => (() => void) | undefined | void,\n\tdeps: unknown[],\n): void {\n\tconst globalEnv = (globalThis as unknown as { env: any })[`env`]\n\tconst isInDev = globalEnv?.NODE_ENV === `development`\n\tif (isInDev) {\n\t\tconst cleanupRef = React.useRef<boolean | (() => void)>(false)\n\t\tReact.useEffect(() => {\n\t\t\tlet cleanupFn = cleanupRef.current\n\t\t\tif (cleanupFn === false) {\n\t\t\t\tcleanupFn = effect() ?? true\n\t\t\t\tcleanupRef.current = cleanupFn\n\t\t\t} else {\n\t\t\t\treturn () => {\n\t\t\t\t\tif (isFn(cleanupFn)) cleanupFn()\n\t\t\t\t\tcleanupRef.current = false\n\t\t\t\t}\n\t\t\t}\n\t\t}, deps)\n\t} else {\n\t\tReact.useEffect(effect, deps)\n\t}\n}\n","/** biome-ignore-all lint/correctness/useHookAtTopLevel: depends on the type of atom, which shouldn't change */\nimport type { ReadableFamilyToken, ReadableToken, ViewOf } from \"atom.io\"\nimport { getFromStore, subscribeToState } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport {\n\tuseCallback,\n\tuseContext,\n\tuseId,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from \"react\"\n\nimport { parseStateOverloads } from \"./parse-state-overloads\"\nimport { StoreContext } from \"./store-context\"\nimport { useSingleEffect } from \"./use-single-effect\"\n\nexport function useO<T, E = never>(\n\ttoken: ReadableToken<T, any, E>,\n): ViewOf<E | T>\n\nexport function useO<T, K extends Canonical, E = never>(\n\ttoken: ReadableFamilyToken<T, K, E>,\n\tkey: NoInfer<K>,\n): ViewOf<E | T>\n\nexport function useO<T, K extends Canonical, E = never>(\n\t...params:\n\t\t| [ReadableFamilyToken<T, K, E>, NoInfer<K>]\n\t\t| [ReadableToken<T, any, E>]\n): ViewOf<E | T> {\n\tconst store = useContext(StoreContext)\n\tconst token = parseStateOverloads(store, ...params)\n\tconst id = useId()\n\n\tif (\n\t\ttoken.type === `mutable_atom` ||\n\t\ttoken.type === `readonly_held_selector` ||\n\t\ttoken.type === `writable_held_selector`\n\t) {\n\t\tconst [, dispatch] = useState<number>(0)\n\t\tconst valueRef = useRef<ViewOf<E | T>>(getFromStore(store, token))\n\t\tuseSingleEffect(() => {\n\t\t\tconst unsub = subscribeToState<T, E>(\n\t\t\t\tstore,\n\t\t\t\ttoken,\n\t\t\t\t`use-o:${id}`,\n\t\t\t\t({ newValue }) => {\n\t\t\t\t\tvalueRef.current = newValue\n\t\t\t\t\tdispatch((c) => c + 1)\n\t\t\t\t},\n\t\t\t)\n\t\t\treturn unsub\n\t\t}, [token.key])\n\t\treturn valueRef.current\n\t}\n\n\tconst sub = useCallback(\n\t\t(dispatch: () => void) =>\n\t\t\tsubscribeToState<T, E>(store, token, `use-o:${id}`, dispatch),\n\t\t[token.key],\n\t)\n\tconst get = useCallback(() => getFromStore(store, token), [token.key])\n\treturn useSyncExternalStore<ViewOf<E | T>>(sub, get, get)\n}\n","import type { MutableAtomFamilyToken, MutableAtomToken } from \"atom.io\"\nimport type { AsJSON, Transceiver } from \"atom.io/internal\"\nimport { findInStore, getJsonToken } from \"atom.io/internal\"\nimport type { Canonical, Json } from \"atom.io/json\"\nimport { useContext } from \"react\"\n\nimport { StoreContext } from \"./store-context\"\nimport { useO } from \"./use-o\"\n\nexport function useJSON<T extends Transceiver<any, any, any>>(\n\ttoken: MutableAtomToken<T>,\n): AsJSON<T>\n\nexport function useJSON<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n>(token: MutableAtomFamilyToken<T, K>, key: NoInfer<K>): AsJSON<T>\n\nexport function useJSON(\n\ttoken: MutableAtomFamilyToken<any, any> | MutableAtomToken<any>,\n\tkey?: Canonical,\n): Json.Serializable {\n\tconst store = useContext(StoreContext)\n\tconst stateToken: MutableAtomToken<any> =\n\t\ttoken.type === `mutable_atom_family` ? findInStore(store, token, key) : token\n\tconst jsonToken = getJsonToken(store, stateToken)\n\treturn useO(jsonToken)\n}\n","/** biome-ignore-all lint/correctness/useHookAtTopLevel: params are used in an invariant way */\nimport type {\n\tLoadable,\n\tReadableFamilyToken,\n\tReadableToken,\n\tViewOf,\n} from \"atom.io\"\nimport { findInStore, type ReadableState, withdraw } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport { useContext, useRef } from \"react\"\n\nexport function useLoadable<T, E>(\n\ttoken: ReadableToken<Loadable<T>, any, E>,\n): `LOADING` | { loading: boolean; value: ViewOf<E | T> }\n\nexport function useLoadable<T, K extends Canonical, E>(\n\ttoken: ReadableFamilyToken<Loadable<T>, K, E>,\n\tkey: NoInfer<K>,\n): `LOADING` | { loading: boolean; value: ViewOf<E | T> }\n\nexport function useLoadable<T, F extends T, E>(\n\ttoken: ReadableToken<Loadable<T>, any, E>,\n\tfallback: F,\n): { loading: boolean; value: ViewOf<T>; error?: E }\n\nexport function useLoadable<T, K extends Canonical, F extends T, E>(\n\ttoken: ReadableFamilyToken<Loadable<T>, K, E>,\n\tkey: NoInfer<K>,\n\tfallback: F,\n): { loading: boolean; value: ViewOf<T>; error?: E }\n\nexport function useLoadable(\n\t...params:\n\t\t| readonly [ReadableFamilyToken<any, Canonical, any>, Canonical, unknown]\n\t\t| readonly [ReadableFamilyToken<any, Canonical, any>, Canonical]\n\t\t| readonly [ReadableToken<any, any, any>, unknown]\n\t\t| readonly [ReadableToken<any, any, any>]\n): `LOADING` | { loading: boolean; value: unknown; error?: unknown } {\n\tconst store = useContext(StoreContext)\n\n\tlet value: unknown\n\tlet state: ReadableState<any, any>\n\tlet fallback: unknown\n\n\tconst [token] = params\n\tlet key: Canonical\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\tcase `readonly_held_selector`:\n\t\tcase `readonly_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\tcase `writable_pure_selector`:\n\t\t\tvalue = useO(token)\n\t\t\tstate = withdraw(store, token)\n\t\t\tfallback = params[1]\n\t\t\tbreak\n\t\tcase `atom_family`:\n\t\tcase `mutable_atom_family`:\n\t\tcase `readonly_held_selector_family`:\n\t\tcase `readonly_pure_selector_family`:\n\t\tcase `writable_held_selector_family`:\n\t\tcase `writable_pure_selector_family`:\n\t\t\tkey = params[1] as Canonical\n\t\t\tvalue = useO(token, key)\n\t\t\tstate = withdraw(store, findInStore(store, token, key))\n\t\t\tfallback = params[2]\n\t}\n\n\tconst hasFallback = fallback !== undefined\n\tconst isErr = `catch` in state && state.catch.some((E) => value instanceof E)\n\n\tconst wrapperRef = useRef<{\n\t\tloading: boolean\n\t\tvalue: unknown\n\t\terror?: unknown\n\t}>({ loading: false, value: null as unknown })\n\tconst lastLoadedRef = useRef(\n\t\tfallback ?? (value instanceof Promise ? `LOADING` : value),\n\t)\n\n\tconst { current: lastLoaded } = lastLoadedRef\n\tlet { current: wrapper } = wrapperRef\n\n\tconst wasErr =\n\t\t`catch` in state && state.catch.some((E) => lastLoaded instanceof E)\n\n\tif (value instanceof Promise) {\n\t\tif (lastLoaded === `LOADING`) {\n\t\t\treturn `LOADING`\n\t\t}\n\t\tif (wasErr && hasFallback) {\n\t\t\twrapper = wrapperRef.current = {\n\t\t\t\tloading: true,\n\t\t\t\tvalue: fallback,\n\t\t\t\terror: lastLoaded,\n\t\t\t}\n\t\t} else {\n\t\t\twrapper = wrapperRef.current = { loading: true, value: lastLoaded }\n\t\t}\n\t} else {\n\t\tlastLoadedRef.current = value\n\t\tif (wrapper.loading === true) {\n\t\t\tif (isErr && hasFallback) {\n\t\t\t\twrapper = wrapperRef.current = {\n\t\t\t\t\tloading: false,\n\t\t\t\t\tvalue: fallback,\n\t\t\t\t\terror: value,\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\twrapper = wrapperRef.current = { loading: false, value: value }\n\t\t\t}\n\t\t} else {\n\t\t\tif (isErr && hasFallback) {\n\t\t\t\twrapper.loading = false\n\t\t\t\twrapper.value = fallback\n\t\t\t\twrapper.error = value\n\t\t\t} else {\n\t\t\t\twrapper.loading = false\n\t\t\t\twrapper.value = value\n\t\t\t\tdelete wrapper.error\n\t\t\t}\n\t\t}\n\t}\n\n\treturn wrapper\n}\n","import type { TimelineToken } from \"atom.io\"\nimport { redo, undo } from \"atom.io\"\nimport { subscribeToTimeline, withdraw } from \"atom.io/internal\"\nimport { useContext, useId, useRef, useSyncExternalStore } from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport type TimelineMeta = {\n\tat: number\n\tlength: number\n\tundo: () => void\n\tredo: () => void\n}\n\nexport function useTL(token: TimelineToken<any>): TimelineMeta {\n\tconst store = useContext(StoreContext)\n\tconst id = useId()\n\tconst timeline = withdraw(store, token)\n\tconst tokenRef = useRef(token)\n\tconst rebuildMeta = () => {\n\t\treturn {\n\t\t\tat: timeline.at,\n\t\t\tlength: timeline.history.length,\n\t\t\tundo: () => {\n\t\t\t\tundo(token)\n\t\t\t},\n\t\t\tredo: () => {\n\t\t\t\tredo(token)\n\t\t\t},\n\t\t}\n\t}\n\tconst meta = useRef<TimelineMeta>(rebuildMeta())\n\tconst retrieve = () => {\n\t\tif (\n\t\t\tmeta.current.at !== timeline?.at ||\n\t\t\tmeta.current.length !== timeline?.history.length ||\n\t\t\ttokenRef.current !== token\n\t\t) {\n\t\t\ttokenRef.current = token\n\t\t\tmeta.current = rebuildMeta()\n\t\t}\n\t\treturn meta.current\n\t}\n\treturn useSyncExternalStore<TimelineMeta>(\n\t\t(dispatch) => subscribeToTimeline(store, token, `use-tl:${id}`, dispatch),\n\t\tretrieve,\n\t\tretrieve,\n\t)\n}\n"],"mappings":";;;;;;;;AAIA,MAAa,eAAyC,cACrD,SAAS,MACT;AAED,MAAa,iBAGP,EAAE,UAAU,QAAQ,SAAS,YAClC,oBAAC,aAAa;CAAS,OAAO;CAAQ;EAAiC;;;;ACcxE,SAAgB,aAKf,GAAG,QAOC;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM,QAAQ,WAAW,aAAa;AACtC,KAAI,OAAO,WAAW,GAAG;EACxB,MAAM,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ACnB,QAAK,UAAU,aAAa;;AAE7B,SAAO,KAAK;;AAEb,QAAO,sBACL,aAAa,oBAAoB,OAAO,OAAO,UAAU,MAAM,SAAS,EACzE,UACA,SACA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atom.io",
3
- "version": "0.46.21",
3
+ "version": "0.46.23",
4
4
  "description": "Composable and testable reactive data library.",
5
5
  "homepage": "https://atom.io.fyi",
6
6
  "sideEffects": false,
@@ -60,21 +60,21 @@
60
60
  }
61
61
  },
62
62
  "devDependencies": {
63
- "@eslint/core": "1.0.1",
64
- "@storybook/addon-docs": "10.2.1",
65
- "@storybook/addon-onboarding": "10.2.1",
66
- "@storybook/react-vite": "10.2.1",
63
+ "@eslint/core": "1.1.0",
64
+ "@storybook/addon-docs": "10.2.7",
65
+ "@storybook/addon-onboarding": "10.2.7",
66
+ "@storybook/react-vite": "10.2.7",
67
67
  "@testing-library/react": "16.3.2",
68
68
  "@types/eslint": "9.6.1",
69
69
  "@types/estree": "1.0.8",
70
70
  "@types/http-proxy": "1.17.17",
71
71
  "@types/node": "25.0.10",
72
- "@types/react": "19.2.10",
72
+ "@types/react": "19.2.13",
73
73
  "@types/tmp": "0.2.6",
74
74
  "@typescript-eslint/parser": "8.54.0",
75
75
  "@typescript-eslint/rule-tester": "8.54.0",
76
76
  "@typescript-eslint/utils": "8.54.0",
77
- "@typescript/native-preview": "7.0.0-dev.20260127.1",
77
+ "@typescript/native-preview": "7.0.0-dev.20260205.1",
78
78
  "@vitest/coverage-v8": "4.0.18",
79
79
  "@vitest/ui": "4.0.18",
80
80
  "arktype": "2.1.29",
@@ -82,20 +82,20 @@
82
82
  "drizzle-kit": "0.31.8",
83
83
  "drizzle-orm": "0.45.1",
84
84
  "eslint": "9.39.2",
85
- "happy-dom": "20.4.0",
85
+ "happy-dom": "20.5.0",
86
86
  "http-proxy": "1.18.1",
87
- "motion": "12.29.2",
87
+ "motion": "12.33.0",
88
88
  "postgres": "3.4.8",
89
- "preact": "10.28.2",
89
+ "preact": "10.28.3",
90
90
  "react": "19.2.4",
91
91
  "react-dom": "19.2.4",
92
92
  "react-router-dom": "7.13.0",
93
93
  "recoverage": "0.1.13",
94
94
  "socket.io": "4.8.3",
95
95
  "socket.io-client": "4.8.3",
96
- "storybook": "10.2.1",
96
+ "storybook": "10.2.7",
97
97
  "tmp": "0.2.5",
98
- "tsdown": "0.20.1",
98
+ "tsdown": "0.20.3",
99
99
  "typescript": "5.9.3",
100
100
  "vite": "7.3.1",
101
101
  "vite-tsconfig-paths": "6.0.5",
@@ -3,8 +3,7 @@ import type {
3
3
  RegularAtomFamilyToken,
4
4
  RegularAtomToken,
5
5
  } from "atom.io"
6
- import { setState } from "atom.io"
7
- import { findInStore } from "atom.io/internal"
6
+ import { findInStore, setIntoStore } from "atom.io/internal"
8
7
  import type { Canonical } from "atom.io/json"
9
8
  import { useContext, useEffect } from "react"
10
9
 
@@ -20,7 +19,7 @@ export function useAtomicRef<
20
19
  K extends Canonical,
21
20
  R extends { current: T | null },
22
21
  >(
23
- token: RegularAtomFamilyToken<T | null, string>,
22
+ token: RegularAtomFamilyToken<T | null, K>,
24
23
  key: NoInfer<K>,
25
24
  useRef: <TT>(initialValue: TT | null) => R,
26
25
  ): R
@@ -52,7 +51,7 @@ export function useAtomicRef<
52
51
  }
53
52
  const ref = useRef(null)
54
53
  useEffect(() => {
55
- setState(token, ref.current)
54
+ setIntoStore(store, token, ref.current)
56
55
  }, [token])
57
56
  return ref
58
57
  }