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
2 changes: 1 addition & 1 deletion synapse/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def yamlload(*paths):
with io.open(path, 'rb') as fd:
return yamlloads(fd)

def yamldump(obj, stream: typing.Optional[typing.BinaryIO] =None) -> bytes:
def yamldump(obj, stream=None):
'''
Dump a object to yaml.

Expand Down
42 changes: 34 additions & 8 deletions synapse/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,9 +973,29 @@ def addDataModels(self, mods):
ctors[name] = (name, ctor, opts, info)

# load all the types in order...
typetodo = {}
for _, mdef in mods:
for typename, (basename, typeopts), typeinfo in mdef.get('types', ()):
self.addType(typename, basename, typeopts, typeinfo, skipinit=True)
for typename, basetype, typeopts in mdef.get('types', ()):
typetodo[typename] = (basetype, typeopts)

def _addType(typename, basetype, typeinfo):

if self.types.get(typename) is not None:
return

# see if we can resolve our base type if it's not loaded yet
if self.types.get(basetype[0]) is None:
todo = typetodo.get(basetype[0])
if todo is None:
mesg = f'No such base type {basetype[0]} for type {typename}.'
raise s_exc.NoSuchType(mesg=mesg)

_addType(basetype[0], todo[0], todo[1])

self.addType(typename, basetype[0], basetype[1], typeinfo, skipinit=True)

for (typename, (basetype, typeinfo)) in typetodo.items():
_addType(typename, basetype, typeinfo)

# finish initializing types
for name, tobj in self.types.items():
Expand Down Expand Up @@ -1152,7 +1172,8 @@ def addType(self, typename, basename, typeopts, typeinfo, skipinit=False):

base = self.types.get(basename)
if base is None:
raise s_exc.NoSuchType(name=basename)
mesg = f'No such base type: {basename} for type {typename}.'
raise s_exc.NoSuchType(mesg=mesg, name=basename)

newtype = base.extend(typename, typeopts, typeinfo, skipinit=skipinit)

Expand Down Expand Up @@ -1229,11 +1250,12 @@ def addForm(self, formname, forminfo, propdefs, checks=True):
if prop.ifaces:
continue

if (newdef := ptypes.get(prop.name)) is not None:
if newdef != prop.typedef:
mesg = f'Form {formname} overrides inherited prop {prop.name} with a different typedef.'
raise s_exc.BadPropDef(mesg=mesg, typedef=newdef, form=formname, prop=prop.name)
continue
# TODO: this should check for a common base type...
# if (newdef := ptypes.get(prop.name)) is not None:
# if newdef != prop.typedef:
# mesg = f'Form {formname} overrides inherited prop {prop.name} with a different typedef.'
# raise s_exc.BadPropDef(mesg=mesg, typedef=newdef, form=formname, prop=prop.name)
# continue

pprops.append((prop.name, prop.typedef, prop.info))

Expand Down Expand Up @@ -1390,6 +1412,10 @@ def addIface(self, name, info):

self.ifaces[name] = info

# FIXME polyprops
if self.types.get(name) is None:
self.addType(name, 'ndef', {'interface': name}, {'doc': 'FIXME POLYPROP PLACE HOLDER'})

def reqTypeNotInUse(self, typename):
if self.propsbytype.get(typename):
mesg = f'Cannot delete type {typename} as it is still in use by properties.'
Expand Down
159 changes: 130 additions & 29 deletions synapse/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,44 @@
'doc': 'A hierarchical taxonomy of timeline types.'}),

('meta:event', ('guid', {}), {
'doc': 'An analytically relevant event in a curated timeline.'}),
'template': {'title': 'event'},
'interfaces': (
('base:event', {}),
),
'props': (
('title', ('str', {}), {
'doc': 'A title for the {title}.'}),

('desc', ('text', {}), {
'doc': 'A description of the {title}.'}),

('type', ('meta:event:type:taxonomy', {}), {
'doc': 'The type of event.'}),
),
'doc': 'An analytically relevant event.'}),

('meta:activity', ('guid', {}), {
'template': {'title': 'activity'},
'interfaces': (
('base:activity', {}),
),
'props': (
('name', ('base:name', {}), {
'doc': 'The name of the {title}.'}),

('desc', ('text', {}), {
'doc': 'A description of the {title}.'}),

('type', ('meta:event:type:taxonomy', {}), {
'doc': 'The type of activity.'}),
),
'doc': 'Analytically relevant activity.'}),

('meta:event:type:taxonomy', ('taxonomy', {}), {
'interfaces': (
('meta:taxonomy', {}),
),
'props': (),
'doc': 'A hierarchical taxonomy of event types.'}),

('meta:ruleset:type:taxonomy', ('taxonomy', {}), {
Expand Down Expand Up @@ -133,12 +165,6 @@
},
'doc': 'A node which represents an aggregate count of a specific type.'}),

('meta:havable', ('ndef', {'interface': 'meta:havable'}), {
'doc': 'An item which may be possessed by an entity.'}),

('meta:discoverable', ('ndef', {'interface': 'meta:discoverable'}), {
'doc': 'FIXME polyprop place holder'}),

('text', ('str', {'strip': False}), {
'doc': 'A multi-line, free form text string.'}),

Expand Down Expand Up @@ -169,6 +195,37 @@
('meta:taxonomy', {}),
),
'doc': 'A hierarchical taxonomy of technique types.'}),

('meta:award:type:taxonomy', ('taxonomy', {}), {
'interfaces': (
('meta:taxonomy', {}),
),
'doc': 'A hierarchical taxonomy of award types.'}),

('meta:award', ('guid', {}), {
'template': {'title': 'award'},
'interfaces': (
('meta:awardable', {}),
),
'props': (
('name', ('base:name', {}), {
'ex': 'nobel peace prize',
'doc': 'The name of the award.'}),

('desc', ('text', {}), {
'doc': 'A description of the award.'}),

# TODO: are award types really a thing?
('type', ('meta:award:type:taxonomy', {}), {
'doc': 'The type of award.'}),

('issuer', ('entity:actor', {}), {
'doc': 'The entity who issues the award.'}),

('period', ('ival', {}), {
'doc': 'The period of time when the award was being issued.'}),
),
'doc': 'An award which can be granted to an actor.'}),
),
'interfaces': (

Expand All @@ -181,6 +238,25 @@
),
}),

('meta:promotable', {
'props': (
('website', ('inet:url', {}), {
'doc': 'The URL of the {title} website.'}),

('social:accounts', ('array', {'type': 'inet:service:account'}), {
'doc': 'Social media accounts for the {title}.'}),
),
'doc': 'Properties common to promoted events or activities.'}),

('meta:attendable', {
'interfaces': (
('base:activity', {}),
),
'doc': 'An interface implemented by activities which may be attended.'}),

('meta:sponsorable', {
'doc': 'An interface implemented by activities which may be sponsored.'}),

('meta:havable', {
'doc': 'An interface used to describe items that can be possessed by an entity.',
'template': {'title': 'item'},
Expand Down Expand Up @@ -216,21 +292,21 @@
},
'props': (

('id', ('meta:id', {}), {
('id', ('base:id', {}), {
'alts': ('ids',),
'doc': 'A unique ID given to the {title}.'}),

('ids', ('array', {'type': 'meta:id'}), {
('ids', ('array', {'type': 'base:id'}), {
'doc': 'An array of alternate IDs given to the {title}.'}),

('url', ('inet:url', {}), {
'doc': 'The URL for the {title}.'}),

('name', ('meta:name', {}), {
('name', ('base:name', {}), {
'alts': ('names',),
'doc': 'The primary name of the {title}.'}),

('names', ('array', {'type': 'meta:name'}), {
('names', ('array', {'type': 'base:name'}), {
'doc': 'A list of alternate names for the {title}.'}),

('desc', ('text', {}), {
Expand Down Expand Up @@ -288,6 +364,37 @@
),
}),

('meta:causal', {
'doc': 'Implemented by events and activities which can lead to effects.'}),

('base:event', {
'template': {'title': 'event'},
'interfaces': (
('meta:causal', {}),
),
'props': (
('time', ('time', {}), {
'doc': 'The time that the {title} occurred.'}),

('activity', ('meta:activity', {}), {
'doc': 'A parent activity which includes this {title}.'}),
),
'doc': 'Properties common to an event.'}),

('base:activity', {
'template': {'title': 'activity'},
'interfaces': (
('meta:causal', {}),
),
'props': (
('period', ('ival', {}), {
'doc': 'The period over which the {title} occurred.'}),

('activity', ('meta:activity', {}), {
'doc': 'A parent activity which includes this {title}.'}),
),
'doc': 'Properties common to activity which occurs over a period.'}),

('meta:usable', {
'template': {'title': 'item'},
'props': (
Expand All @@ -296,6 +403,15 @@
),
'doc': 'An interface for forms which can be used by an actor.'}),

('meta:competitive', {
'doc': 'An interface implemented by organized competitive activities.'}),

('meta:awardable', {
'doc': 'An interface implemented by forms which may be awarded to an actor.'}),

('meta:believable', {
'doc': 'An interface for forms which may be believed in by an actor.'}),

('meta:matchish', {
'doc': 'Properties which are common to matches based on rules.',
'template': {'rule': 'rule', 'rule:type': 'rule:type',
Expand Down Expand Up @@ -367,6 +483,9 @@

(('meta:technique', 'addresses', 'risk:vuln'), {
'doc': 'The technique addresses the vulnerability.'}),

(('meta:causal', 'ledto', 'meta:causal'), {
'doc': 'The source event led to the target event.'}),
),
'forms': (

Expand Down Expand Up @@ -474,24 +593,6 @@
('meta:timeline:type:taxonomy', {
'prevnames': ('meta:timeline:taxonomy',)}, ()),

('meta:event', {}, (

('period', ('ival', {}), {
'doc': 'The period over which the event occurred.'}),

('title', ('str', {}), {
'doc': 'A title for the event.'}),

('desc', ('text', {}), {
'doc': 'A description of the event.'}),

('type', ('meta:event:type:taxonomy', {}), {
'doc': 'Type of event.'}),
)),

('meta:event:type:taxonomy', {
'prevnames': ('meta:event:taxonomy',)}, ()),

('meta:ruleset', {}, (

('name', ('base:id', {}), {
Expand Down
25 changes: 6 additions & 19 deletions synapse/models/belief.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
'types': (

('belief:system', ('guid', {}), {
'interfaces': (
('meta:believable', {}),
),
'doc': 'A belief system such as an ideology, philosophy, or religion.'}),

('belief:system:type:taxonomy', ('taxonomy', {}), {
Expand All @@ -12,10 +15,10 @@
'doc': 'A hierarchical taxonomy of belief system types.'}),

('belief:tenet', ('guid', {}), {
'interfaces': (
('meta:believable', {}),
),
'doc': 'A concrete tenet potentially shared by multiple belief systems.'}),

('belief:subscriber', ('guid', {}), {
'doc': 'A contact which subscribes to a belief system.'}),
),
'forms': (

Expand All @@ -32,7 +35,6 @@

('began', ('time', {}), {
'doc': 'The time that the belief system was first observed.'}),

)),

('belief:system:type:taxonomy', {}, ()),
Expand All @@ -46,26 +48,11 @@
'doc': 'A description of the tenet.'}),
)),

('belief:subscriber', {}, (

('contact', ('entity:individual', {}), {
'doc': 'The individual who subscribes to the belief system.'}),

('system', ('belief:system', {}), {
'doc': 'The belief system to which the contact subscribes.'}),

('period', ('ival', {}), {
'prevnames': ('began', 'ended'),
'doc': 'The time period when the contact subscribed to the belief system.'}),
)),
),
'edges': (

(('belief:system', 'has', 'belief:tenet'), {
'doc': 'The belief system includes the tenet.'}),

(('belief:subscriber', 'follows', 'belief:tenet'), {
'doc': 'The subscriber is assessed to generally adhere to the specific tenet.'}),
),
}),
)
Loading