-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsys-attachment.object.ts
More file actions
142 lines (127 loc) · 4.43 KB
/
Copy pathsys-attachment.object.ts
File metadata and controls
142 lines (127 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { ObjectSchema, Field } from '@objectstack/spec/data';
/**
* sys_attachment — Polymorphic File ↔ Record Link
*
* Generic join row that attaches a previously-uploaded `sys_file` to
* any other record. Mirrors the Salesforce "ContentDocumentLink" /
* ServiceNow "sys_attachment" pattern: file storage and "where this
* file is attached" are separated, so the same `sys_file` row can be
* surfaced on multiple records, an org-wide library, or a thread.
*
* Conventions:
* - `parent_object` is the short object name (e.g. `account`, `lead`,
* `opportunity`, `case`, `sys_comment`).
* - `parent_id` is the parent record's primary key.
* - `(parent_object, parent_id)` is the natural index for the
* "files on this record" lookup.
* - Access is derived from the PARENT record (Salesforce semantics),
* enforced by service-storage's attachment access hooks (#2755).
* Salesforce's `ShareType`/`Visibility` dials were modeled here in v1
* but had no runtime consumer — removed per ADR-0049 enforce-or-remove;
* reintroduce them together with their enforcement if ever needed.
*
* @namespace sys
*/
export const SysAttachment = ObjectSchema.create({
name: 'sys_attachment',
label: 'Attachment',
pluralLabel: 'Attachments',
icon: 'paperclip',
isSystem: true,
managedBy: 'platform',
description: 'Polymorphic link between a sys_file and any other record',
titleFormat: '{file_name} → {parent_object}/{parent_id}',
highlightFields: ['created_at', 'parent_object', 'file_name', 'mime_type', 'size'],
fields: {
id: Field.text({
label: 'Attachment ID',
required: true,
readonly: true,
group: 'System',
}),
// ── Parent (polymorphic) ────────────────────────────────────
parent_object: Field.text({
label: 'Parent Object',
required: true,
searchable: true,
maxLength: 128,
description: 'Short object name of the attached-to record (e.g. account, lead)',
group: 'Parent',
}),
parent_id: Field.text({
label: 'Parent Record',
required: true,
searchable: true,
maxLength: 64,
description: 'Primary key of the attached-to record',
group: 'Parent',
}),
// ── File reference ──────────────────────────────────────────
file_id: Field.lookup('sys_file', {
label: 'File',
required: true,
description: 'The sys_file storage entry being attached',
group: 'File',
}),
file_name: Field.text({
label: 'File Name',
required: false,
searchable: true,
maxLength: 255,
description: 'Denormalised copy of sys_file.name for fast list rendering',
group: 'File',
}),
mime_type: Field.text({
label: 'MIME Type',
required: false,
maxLength: 128,
group: 'File',
}),
size: Field.number({
label: 'Size (bytes)',
required: false,
group: 'File',
}),
// ── Authoring ──────────────────────────────────────────────
uploaded_by: Field.lookup('sys_user', {
label: 'Uploaded By',
required: false,
group: 'System',
}),
description: Field.textarea({
label: 'Description',
required: false,
maxLength: 1024,
group: 'File',
}),
created_at: Field.datetime({
label: 'Created At',
required: true,
defaultValue: 'NOW()',
readonly: true,
group: 'System',
}),
updated_at: Field.datetime({
label: 'Updated At',
required: false,
group: 'System',
}),
},
indexes: [
{ fields: ['parent_object', 'parent_id', 'created_at'] },
{ fields: ['file_id'] },
{ fields: ['uploaded_by'] },
],
enable: {
trackHistory: false,
searchable: true,
apiEnabled: true,
// [#2970 item 5 / ADR-0049] `trash` is `dead` in the liveness ledger (no
// engine soft-delete reader) and attachment deletes ARE hard (#2755): the
// reap guard reclaims a file's bytes once its last join row is gone, so a
// "restore" would dangle. Declare `false` — the honest state — rather than
// claim a restore capability the runtime does not provide.
clone: false,
},
});